Re: [PATCH rfc -next 01/10] mm: add a generic VMA lock-based page fault handler

2023-07-13 Thread Kefeng Wang




On 2023/7/14 4:12, Suren Baghdasaryan wrote:

On Thu, Jul 13, 2023 at 9:15 AM Matthew Wilcox  wrote:



+int try_vma_locked_page_fault(struct vm_locked_fault *vmlf, vm_fault_t *ret)
+{
+ struct vm_area_struct *vma;
+ vm_fault_t fault;



On Thu, Jul 13, 2023 at 05:53:29PM +0800, Kefeng Wang wrote:

+#define VM_LOCKED_FAULT_INIT(_name, _mm, _address, _fault_flags, _vm_flags, 
_regs, _fault_code) \
+ _name.mm= _mm;  \
+ _name.address   = _address; \
+ _name.fault_flags   = _fault_flags; \
+ _name.vm_flags  = _vm_flags;\
+ _name.regs  = _regs;\
+ _name.fault_code= _fault_code


More consolidated code is a good idea; no question.  But I don't think
this is the right way to do it.


I agree it is not good enough, but the arch's vma check acess has
different implementation, some use vm flags, some need fault code and
regs, and some use both :(




+int __weak arch_vma_check_access(struct vm_area_struct *vma,
+  struct vm_locked_fault *vmlf);


This should be:

#ifndef vma_check_access
bool vma_check_access(struct vm_area_struct *vma, )
{
 return (vma->vm_flags & vm_flags) == 0;
}
#endif

and then arches which want to do something different can just define
vma_check_access.


Ok, I could convert to use this way.




+int try_vma_locked_page_fault(struct vm_locked_fault *vmlf, vm_fault_t *ret)
+{
+ struct vm_area_struct *vma;
+ vm_fault_t fault;


Declaring the vmf in this function and then copying it back is just wrong.
We need to declare vm_fault_t earlier (in the arch fault handler) and
pass it in.


Actually I passed the vm_fault_t *ret(in the arch fault handler), we
could directly use *ret instead of a new local variable, and no copy.


Did you mean to say "we need to declare vmf (struct vm_fault) earlier
(in the arch fault handler) and pass it in." ?


  I don't think that creating struct vm_locked_fault is the
right idea either.


As mentioned above for vma check access, we need many arguments for a 
function, a new struct looks possible better, is there better solution

or any suggestion?

Thanks.




+ if (!(vmlf->fault_flags & FAULT_FLAG_USER))
+ return -EINVAL;
+
+ vma = lock_vma_under_rcu(vmlf->mm, vmlf->address);
+ if (!vma)
+ return -EINVAL;
+
+ if (arch_vma_check_access(vma, vmlf)) {
+ vma_end_read(vma);
+ return -EINVAL;
+ }
+
+ fault = handle_mm_fault(vma, vmlf->address,
+ vmlf->fault_flags | FAULT_FLAG_VMA_LOCK,
+ vmlf->regs);
+ *ret = fault;
+
+ if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
+ vma_end_read(vma);
+
+ if ((fault & VM_FAULT_RETRY))
+ count_vm_vma_lock_event(VMA_LOCK_RETRY);
+ else
+ count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
+
+ return 0;
+}
+
  #endif /* CONFIG_PER_VMA_LOCK */

  #ifndef __PAGETABLE_P4D_FOLDED
--
2.27.0




Re: [PATCH 0/2] eventfd: simplify signal helpers

2023-07-13 Thread Alex Williamson
On Thu, 13 Jul 2023 12:05:36 +0200
Christian Brauner  wrote:

> Hey everyone,
> 
> This simplifies the eventfd_signal() and eventfd_signal_mask() helpers
> by removing the count argument which is effectively unused.

We have a patch under review which does in fact make use of the
signaling value:

https://lore.kernel.org/all/20230630155936.3015595-1-...@semihalf.com/

Thanks,
Alex



Re: [PATCH 2/2] eventfd: simplify eventfd_signal_mask()

2023-07-13 Thread Christian Brauner
On Thu, Jul 13, 2023 at 07:33:05AM -0700, Sean Christopherson wrote:
> On Thu, Jul 13, 2023, Christian Brauner wrote:
> > diff --git a/fs/eventfd.c b/fs/eventfd.c
> > index dc9e01053235..077be5da72bd 100644
> > --- a/fs/eventfd.c
> > +++ b/fs/eventfd.c
> > @@ -43,9 +43,10 @@ struct eventfd_ctx {
> > int id;
> >  };
> >  
> > -__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask)
> > +bool eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask)
> >  {
> > unsigned long flags;
> > +   __u64 n = 1;
> >  
> > /*
> >  * Deadlock or stack overflow issues can happen if we recurse here
> > @@ -68,7 +69,7 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 
> > n, __poll_t mask)
> > current->in_eventfd = 0;
> > spin_unlock_irqrestore(>wqh.lock, flags);
> >  
> > -   return n;
> > +   return n == 1;
> >  }
> 
> ...
> 
> > @@ -58,13 +58,12 @@ static inline struct eventfd_ctx *eventfd_ctx_fdget(int 
> > fd)
> > return ERR_PTR(-ENOSYS);
> >  }
> >  
> > -static inline int eventfd_signal(struct eventfd_ctx *ctx)
> > +static inline bool eventfd_signal(struct eventfd_ctx *ctx)
> >  {
> > return -ENOSYS;
> >  }
> >  
> > -static inline int eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n,
> > - unsigned mask)
> > +static inline bool eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned 
> > mask)
> >  {
> > return -ENOSYS;
> 
> This will morph to "true" for what should be an error case.  One option would 
> be

Ewww, that means it did return -ENOSYS before any of this.

> to have eventfd_signal_mask() return 0/-errno instead of the count, but 
> looking
> at all the callers, nothing ever actually consumes the result.
> 
> KVMGT morphs failure into -EFAULT
> 
>   if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger, 1) != 1)
>   return -EFAULT;
> 
> but the only caller of that user ignores the return value.
> 
>   if (vgpu_vreg(vgpu, i915_mmio_reg_offset(GEN8_MASTER_IRQ))
>   & ~GEN8_MASTER_IRQ_CONTROL)
>   inject_virtual_interrupt(vgpu);
> 
> The sample driver in samples/vfio-mdev/mtty.c uses a similar pattern: prints 
> an
> error but otherwise ignores the result.
> 
> So why not return nothing?  That will simplify eventfd_signal_mask() a wee bit
> more, and eliminate that bizarre return value confusion for the ugly stubs, 
> e.g.

Yeah, it used to return an int in the non-eventfd and a __u64 in the
eventfd case.

> 
> void eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned mask)
> {
>   unsigned long flags;
> 
>   /*
>* Deadlock or stack overflow issues can happen if we recurse here
>* through waitqueue wakeup handlers. If the caller users potentially
>* nested waitqueues with custom wakeup handlers, then it should
>* check eventfd_signal_allowed() before calling this function. If
>* it returns false, the eventfd_signal() call should be deferred to a
>* safe context.
>*/
>   if (WARN_ON_ONCE(current->in_eventfd))
>   return;
> 
>   spin_lock_irqsave(>wqh.lock, flags);
>   current->in_eventfd = 1;
>   if (ctx->count < ULLONG_MAX)
>   ctx->count++;
>   if (waitqueue_active(>wqh))
>   wake_up_locked_poll(>wqh, EPOLLIN | mask);
>   current->in_eventfd = 0;
>   spin_unlock_irqrestore(>wqh.lock, flags);
> }
> 
> You could even go further and unify the real and stub versions of 
> eventfd_signal().

The reason I didn't make eventfd_signal_mask() return void was that it
was called from eventfd_signal() which did, I didn't realize the caller
didn't actually consume the return value.

If we can let both return void it gets simpler.

Thanks for that.


Re: [PATCH 2/2] eventfd: simplify eventfd_signal_mask()

2023-07-13 Thread Sean Christopherson
On Thu, Jul 13, 2023, Christian Brauner wrote:
> diff --git a/fs/eventfd.c b/fs/eventfd.c
> index dc9e01053235..077be5da72bd 100644
> --- a/fs/eventfd.c
> +++ b/fs/eventfd.c
> @@ -43,9 +43,10 @@ struct eventfd_ctx {
>   int id;
>  };
>  
> -__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask)
> +bool eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask)
>  {
>   unsigned long flags;
> + __u64 n = 1;
>  
>   /*
>* Deadlock or stack overflow issues can happen if we recurse here
> @@ -68,7 +69,7 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, 
> __poll_t mask)
>   current->in_eventfd = 0;
>   spin_unlock_irqrestore(>wqh.lock, flags);
>  
> - return n;
> + return n == 1;
>  }

...

> @@ -58,13 +58,12 @@ static inline struct eventfd_ctx *eventfd_ctx_fdget(int 
> fd)
>   return ERR_PTR(-ENOSYS);
>  }
>  
> -static inline int eventfd_signal(struct eventfd_ctx *ctx)
> +static inline bool eventfd_signal(struct eventfd_ctx *ctx)
>  {
>   return -ENOSYS;
>  }
>  
> -static inline int eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n,
> -   unsigned mask)
> +static inline bool eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned 
> mask)
>  {
>   return -ENOSYS;

This will morph to "true" for what should be an error case.  One option would be
to have eventfd_signal_mask() return 0/-errno instead of the count, but looking
at all the callers, nothing ever actually consumes the result.

KVMGT morphs failure into -EFAULT

if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger, 1) != 1)
return -EFAULT;

but the only caller of that user ignores the return value.

if (vgpu_vreg(vgpu, i915_mmio_reg_offset(GEN8_MASTER_IRQ))
& ~GEN8_MASTER_IRQ_CONTROL)
inject_virtual_interrupt(vgpu);

The sample driver in samples/vfio-mdev/mtty.c uses a similar pattern: prints an
error but otherwise ignores the result.

So why not return nothing?  That will simplify eventfd_signal_mask() a wee bit
more, and eliminate that bizarre return value confusion for the ugly stubs, e.g.

void eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned mask)
{
unsigned long flags;

/*
 * Deadlock or stack overflow issues can happen if we recurse here
 * through waitqueue wakeup handlers. If the caller users potentially
 * nested waitqueues with custom wakeup handlers, then it should
 * check eventfd_signal_allowed() before calling this function. If
 * it returns false, the eventfd_signal() call should be deferred to a
 * safe context.
 */
if (WARN_ON_ONCE(current->in_eventfd))
return;

spin_lock_irqsave(>wqh.lock, flags);
current->in_eventfd = 1;
if (ctx->count < ULLONG_MAX)
ctx->count++;
if (waitqueue_active(>wqh))
wake_up_locked_poll(>wqh, EPOLLIN | mask);
current->in_eventfd = 0;
spin_unlock_irqrestore(>wqh.lock, flags);
}

You could even go further and unify the real and stub versions of 
eventfd_signal().


Re: [PATCH 1/2] eventfd: simplify eventfd_signal()

2023-07-13 Thread Oded Gabbay
On Thu, Jul 13, 2023 at 1:06 PM Christian Brauner  wrote:
>
> Ever since the evenfd type was introduced back in 2007 in commit
> e1ad7468c77d ("signal/timer/event: eventfd core") the eventfd_signal()
> function only ever passed 1 as a value for @n. There's no point in
> keeping that additional argument.
>
> Signed-off-by: Christian Brauner 
> ---
>  arch/x86/kvm/hyperv.c |  2 +-
>  arch/x86/kvm/xen.c|  2 +-
>  drivers/accel/habanalabs/common/device.c  |  2 +-
>  drivers/fpga/dfl.c|  2 +-
>  drivers/gpu/drm/i915/gvt/interrupt.c  |  2 +-
>  drivers/infiniband/hw/mlx5/devx.c |  2 +-
>  drivers/misc/ocxl/file.c  |  2 +-
>  drivers/s390/cio/vfio_ccw_chp.c   |  2 +-
>  drivers/s390/cio/vfio_ccw_drv.c   |  4 ++--
>  drivers/s390/cio/vfio_ccw_ops.c   |  6 +++---
>  drivers/s390/crypto/vfio_ap_ops.c |  2 +-
>  drivers/usb/gadget/function/f_fs.c|  4 ++--
>  drivers/vdpa/vdpa_user/vduse_dev.c|  6 +++---
>  drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c|  2 +-
>  drivers/vfio/pci/vfio_pci_core.c  |  6 +++---
>  drivers/vfio/pci/vfio_pci_intrs.c | 12 ++--
>  drivers/vfio/platform/vfio_platform_irq.c |  4 ++--
>  drivers/vhost/vdpa.c  |  4 ++--
>  drivers/vhost/vhost.c | 10 +-
>  drivers/vhost/vhost.h |  2 +-
>  drivers/virt/acrn/ioeventfd.c |  2 +-
>  fs/aio.c  |  2 +-
>  fs/eventfd.c  |  9 +++--
>  include/linux/eventfd.h   |  4 ++--
>  mm/memcontrol.c   | 10 +-
>  mm/vmpressure.c   |  2 +-
>  samples/vfio-mdev/mtty.c  |  4 ++--
>  virt/kvm/eventfd.c|  4 ++--
>  28 files changed, 56 insertions(+), 59 deletions(-)
>
> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
> index b28fd020066f..2f4bd74b482c 100644
> --- a/arch/x86/kvm/hyperv.c
> +++ b/arch/x86/kvm/hyperv.c
> @@ -2387,7 +2387,7 @@ static u16 kvm_hvcall_signal_event(struct kvm_vcpu 
> *vcpu, struct kvm_hv_hcall *h
> if (!eventfd)
> return HV_STATUS_INVALID_PORT_ID;
>
> -   eventfd_signal(eventfd, 1);
> +   eventfd_signal(eventfd);
> return HV_STATUS_SUCCESS;
>  }
>
> diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
> index 40edf4d1974c..a7b62bafd57b 100644
> --- a/arch/x86/kvm/xen.c
> +++ b/arch/x86/kvm/xen.c
> @@ -2043,7 +2043,7 @@ static bool kvm_xen_hcall_evtchn_send(struct kvm_vcpu 
> *vcpu, u64 param, u64 *r)
> if (ret < 0 && ret != -ENOTCONN)
> return false;
> } else {
> -   eventfd_signal(evtchnfd->deliver.eventfd.ctx, 1);
> +   eventfd_signal(evtchnfd->deliver.eventfd.ctx);
> }
>
> *r = 0;
> diff --git a/drivers/accel/habanalabs/common/device.c 
> b/drivers/accel/habanalabs/common/device.c
> index b97339d1f7c6..30357b371d61 100644
> --- a/drivers/accel/habanalabs/common/device.c
> +++ b/drivers/accel/habanalabs/common/device.c
> @@ -1963,7 +1963,7 @@ static void hl_notifier_event_send(struct 
> hl_notifier_event *notifier_event, u64
> notifier_event->events_mask |= event_mask;
>
> if (notifier_event->eventfd)
> -   eventfd_signal(notifier_event->eventfd, 1);
> +   eventfd_signal(notifier_event->eventfd);
>
> mutex_unlock(_event->lock);
>  }
> diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
> index dd7a783d53b5..e73f88050f08 100644
> --- a/drivers/fpga/dfl.c
> +++ b/drivers/fpga/dfl.c
> @@ -1872,7 +1872,7 @@ static irqreturn_t dfl_irq_handler(int irq, void *arg)
>  {
> struct eventfd_ctx *trigger = arg;
>
> -   eventfd_signal(trigger, 1);
> +   eventfd_signal(trigger);
> return IRQ_HANDLED;
>  }
>
> diff --git a/drivers/gpu/drm/i915/gvt/interrupt.c 
> b/drivers/gpu/drm/i915/gvt/interrupt.c
> index 68eca023bbc6..3d9e09c2add4 100644
> --- a/drivers/gpu/drm/i915/gvt/interrupt.c
> +++ b/drivers/gpu/drm/i915/gvt/interrupt.c
> @@ -435,7 +435,7 @@ static int inject_virtual_interrupt(struct intel_vgpu 
> *vgpu)
>  */
> if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status))
> return -ESRCH;
> -   if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger, 1) != 1)
> +   if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger) != 1)
> return -EFAULT;
> return 0;
>  }
> diff --git a/drivers/infiniband/hw/mlx5/devx.c 
> b/drivers/infiniband/hw/mlx5/devx.c
> index db5fb196c728..ad50487790ff 100644
> --- a/drivers/infiniband/hw/mlx5/devx.c
> +++ b/drivers/infiniband/hw/mlx5/devx.c
> @@ -2498,7 +2498,7 @@ static void dispatch_event_fd(struct list_head *fd_list,
>
> list_for_each_entry_rcu(item, fd_list, xa_list) {
> if (item->eventfd)
> -   

Re: [PATCH 1/2] eventfd: simplify eventfd_signal()

2023-07-13 Thread Anthony Krowiak

For vfio_ap_ops.c:
Reviewed-by: Tony Krowiak 

On 7/13/23 6:05 AM, Christian Brauner wrote:

Ever since the evenfd type was introduced back in 2007 in commit
e1ad7468c77d ("signal/timer/event: eventfd core") the eventfd_signal()
function only ever passed 1 as a value for @n. There's no point in
keeping that additional argument.

Signed-off-by: Christian Brauner 
---
  arch/x86/kvm/hyperv.c |  2 +-
  arch/x86/kvm/xen.c|  2 +-
  drivers/accel/habanalabs/common/device.c  |  2 +-
  drivers/fpga/dfl.c|  2 +-
  drivers/gpu/drm/i915/gvt/interrupt.c  |  2 +-
  drivers/infiniband/hw/mlx5/devx.c |  2 +-
  drivers/misc/ocxl/file.c  |  2 +-
  drivers/s390/cio/vfio_ccw_chp.c   |  2 +-
  drivers/s390/cio/vfio_ccw_drv.c   |  4 ++--
  drivers/s390/cio/vfio_ccw_ops.c   |  6 +++---
  drivers/s390/crypto/vfio_ap_ops.c |  2 +-
  drivers/usb/gadget/function/f_fs.c|  4 ++--
  drivers/vdpa/vdpa_user/vduse_dev.c|  6 +++---
  drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c|  2 +-
  drivers/vfio/pci/vfio_pci_core.c  |  6 +++---
  drivers/vfio/pci/vfio_pci_intrs.c | 12 ++--
  drivers/vfio/platform/vfio_platform_irq.c |  4 ++--
  drivers/vhost/vdpa.c  |  4 ++--
  drivers/vhost/vhost.c | 10 +-
  drivers/vhost/vhost.h |  2 +-
  drivers/virt/acrn/ioeventfd.c |  2 +-
  fs/aio.c  |  2 +-
  fs/eventfd.c  |  9 +++--
  include/linux/eventfd.h   |  4 ++--
  mm/memcontrol.c   | 10 +-
  mm/vmpressure.c   |  2 +-
  samples/vfio-mdev/mtty.c  |  4 ++--
  virt/kvm/eventfd.c|  4 ++--
  28 files changed, 56 insertions(+), 59 deletions(-)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index b28fd020066f..2f4bd74b482c 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -2387,7 +2387,7 @@ static u16 kvm_hvcall_signal_event(struct kvm_vcpu *vcpu, 
struct kvm_hv_hcall *h
if (!eventfd)
return HV_STATUS_INVALID_PORT_ID;
  
-	eventfd_signal(eventfd, 1);

+   eventfd_signal(eventfd);
return HV_STATUS_SUCCESS;
  }
  
diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c

index 40edf4d1974c..a7b62bafd57b 100644
--- a/arch/x86/kvm/xen.c
+++ b/arch/x86/kvm/xen.c
@@ -2043,7 +2043,7 @@ static bool kvm_xen_hcall_evtchn_send(struct kvm_vcpu 
*vcpu, u64 param, u64 *r)
if (ret < 0 && ret != -ENOTCONN)
return false;
} else {
-   eventfd_signal(evtchnfd->deliver.eventfd.ctx, 1);
+   eventfd_signal(evtchnfd->deliver.eventfd.ctx);
}
  
  	*r = 0;

diff --git a/drivers/accel/habanalabs/common/device.c 
b/drivers/accel/habanalabs/common/device.c
index b97339d1f7c6..30357b371d61 100644
--- a/drivers/accel/habanalabs/common/device.c
+++ b/drivers/accel/habanalabs/common/device.c
@@ -1963,7 +1963,7 @@ static void hl_notifier_event_send(struct 
hl_notifier_event *notifier_event, u64
notifier_event->events_mask |= event_mask;
  
  	if (notifier_event->eventfd)

-   eventfd_signal(notifier_event->eventfd, 1);
+   eventfd_signal(notifier_event->eventfd);
  
  	mutex_unlock(_event->lock);

  }
diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index dd7a783d53b5..e73f88050f08 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -1872,7 +1872,7 @@ static irqreturn_t dfl_irq_handler(int irq, void *arg)
  {
struct eventfd_ctx *trigger = arg;
  
-	eventfd_signal(trigger, 1);

+   eventfd_signal(trigger);
return IRQ_HANDLED;
  }
  
diff --git a/drivers/gpu/drm/i915/gvt/interrupt.c b/drivers/gpu/drm/i915/gvt/interrupt.c

index 68eca023bbc6..3d9e09c2add4 100644
--- a/drivers/gpu/drm/i915/gvt/interrupt.c
+++ b/drivers/gpu/drm/i915/gvt/interrupt.c
@@ -435,7 +435,7 @@ static int inject_virtual_interrupt(struct intel_vgpu *vgpu)
 */
if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status))
return -ESRCH;
-   if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger, 1) != 1)
+   if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger) != 1)
return -EFAULT;
return 0;
  }
diff --git a/drivers/infiniband/hw/mlx5/devx.c 
b/drivers/infiniband/hw/mlx5/devx.c
index db5fb196c728..ad50487790ff 100644
--- a/drivers/infiniband/hw/mlx5/devx.c
+++ b/drivers/infiniband/hw/mlx5/devx.c
@@ -2498,7 +2498,7 @@ static void dispatch_event_fd(struct list_head *fd_list,
  
  	list_for_each_entry_rcu(item, fd_list, xa_list) {

if (item->eventfd)
-   eventfd_signal(item->eventfd, 1);
+   eventfd_signal(item->eventfd);
else
deliver_event(item, 

[PATCH] media: atomisp: void function return statements are not generally useful

2023-07-13 Thread hexingwei001

void function return statements are not generally useful,
so deleted the return in function ia_css_get_crop_offsets().

Signed-off-by: Xingwei He 
---
 drivers/staging/media/atomisp/pci/sh_css.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/media/atomisp/pci/sh_css.c 
b/drivers/staging/media/atomisp/pci/sh_css.c

index 93789500416f..bd0e2451cd08 100644
--- a/drivers/staging/media/atomisp/pci/sh_css.c
+++ b/drivers/staging/media/atomisp/pci/sh_css.c
@@ -3107,7 +3107,6 @@ ia_css_get_crop_offsets(

 IA_CSS_LEAVE_PRIVATE("void start_col: %u start_row: %u", column, 
row);


-return;
 }
 #endif


Re: [PATCH v6 02/14] x86/kexec: refactor for kernel/Kconfig.kexec

2023-07-13 Thread Leizhen (ThunderTown)



On 2023/7/13 0:15, Eric DeVolder wrote:
> The kexec and crash kernel options are provided in the common
> kernel/Kconfig.kexec. Utilize the common options and provide
> the ARCH_SUPPORTS_ and ARCH_SELECTS_ entries to recreate the
> equivalent set of KEXEC and CRASH options.
> 
> Signed-off-by: Eric DeVolder 
> ---
>  arch/x86/Kconfig | 92 ++--
>  1 file changed, 19 insertions(+), 73 deletions(-)
> 
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 7422db409770..9767a343f7c2 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -2040,88 +2040,34 @@ config EFI_RUNTIME_MAP
>  
>  source "kernel/Kconfig.hz"
>  
> -config KEXEC
> - bool "kexec system call"
> - select KEXEC_CORE
> - help
> -   kexec is a system call that implements the ability to shutdown your
> -   current kernel, and to start another kernel.  It is like a reboot
> -   but it is independent of the system firmware.   And like a reboot
> -   you can start any kernel with it, not just Linux.
> -
> -   The name comes from the similarity to the exec system call.
> -
> -   It is an ongoing process to be certain the hardware in a machine
> -   is properly shutdown, so do not be surprised if this code does not
> -   initially work for you.  As of this writing the exact hardware
> -   interface is strongly in flux, so no good recommendation can be
> -   made.
> -
> -config KEXEC_FILE
> - bool "kexec file based system call"
> - select KEXEC_CORE
> - select HAVE_IMA_KEXEC if IMA
> - depends on X86_64
> - depends on CRYPTO=y
> - depends on CRYPTO_SHA256=y
> - help
> -   This is new version of kexec system call. This system call is
> -   file based and takes file descriptors as system call argument
> -   for kernel and initramfs as opposed to list of segments as
> -   accepted by previous system call.
> +config ARCH_SUPPORTS_KEXEC
> + def_bool y

In v5, Joel Fernandes seems to suggest you change it to the following form:
In arch/Kconfig:
+config ARCH_SUPPORTS_KEXEC
+   bool

In arch/x86/Kconfig:
config X86
... ...
+   select ARCH_SUPPORTS_KEXEC

In arch/arm64/Kconfig:
config ARM64
... ...
+   select ARCH_SUPPORTS_KEXEC if PM_SLEEP_SMP

etc..

You can refer to ARCH_HAS_DEBUG_VIRTUAL.

>  
> -config ARCH_HAS_KEXEC_PURGATORY
> - def_bool KEXEC_FILE
> +config ARCH_SUPPORTS_KEXEC_FILE
> + def_bool X86_64 && CRYPTO && CRYPTO_SHA256
>  
> -config KEXEC_SIG
> - bool "Verify kernel signature during kexec_file_load() syscall"
> +config ARCH_SELECTS_KEXEC_FILE
> + def_bool y
>   depends on KEXEC_FILE
> - help
> + select HAVE_IMA_KEXEC if IMA
>  
> -   This option makes the kexec_file_load() syscall check for a valid
> -   signature of the kernel image.  The image can still be loaded without
> -   a valid signature unless you also enable KEXEC_SIG_FORCE, though if
> -   there's a signature that we can check, then it must be valid.
> +config ARCH_HAS_KEXEC_PURGATORY
> + def_bool KEXEC_FILE
>  
> -   In addition to this option, you need to enable signature
> -   verification for the corresponding kernel image type being
> -   loaded in order for this to work.
> +config ARCH_SUPPORTS_KEXEC_SIG
> + def_bool y
>  
> -config KEXEC_SIG_FORCE
> - bool "Require a valid signature in kexec_file_load() syscall"
> - depends on KEXEC_SIG
> - help
> -   This option makes kernel signature verification mandatory for
> -   the kexec_file_load() syscall.
> +config ARCH_SUPPORTS_KEXEC_SIG_FORCE
> + def_bool y
>  
> -config KEXEC_BZIMAGE_VERIFY_SIG
> - bool "Enable bzImage signature verification support"
> - depends on KEXEC_SIG
> - depends on SIGNED_PE_FILE_VERIFICATION
> - select SYSTEM_TRUSTED_KEYRING
> - help
> -   Enable bzImage signature verification support.
> +config ARCH_SUPPORTS_KEXEC_BZIMAGE_VERIFY_SIG
> + def_bool y
>  
> -config CRASH_DUMP
> - bool "kernel crash dumps"
> - depends on X86_64 || (X86_32 && HIGHMEM)
> - help
> -   Generate crash dump after being started by kexec.
> -   This should be normally only set in special crash dump kernels
> -   which are loaded in the main kernel with kexec-tools into
> -   a specially reserved region and then later executed after
> -   a crash by kdump/kexec. The crash dump kernel must be compiled
> -   to a memory address not used by the main kernel or BIOS using
> -   PHYSICAL_START, or it must be built as a relocatable image
> -   (CONFIG_RELOCATABLE=y).
> -   For more details see Documentation/admin-guide/kdump/kdump.rst
> +config ARCH_SUPPORTS_KEXEC_JUMP
> + def_bool y
>  
> -config KEXEC_JUMP
> - bool "kexec jump"
> - depends on KEXEC && HIBERNATION
> - help
> -   Jump between original kernel and kexeced kernel and invoke
> -   code in physical address mode 

[PATCH 2/2] eventfd: simplify eventfd_signal_mask()

2023-07-13 Thread Christian Brauner
The eventfd_signal_mask() helper was introduced for io_uring and similar
to eventfd_signal() it always passed 1 for @n. So don't bother with that
argument at all.

Signed-off-by: Christian Brauner 
---
 drivers/gpu/drm/i915/gvt/interrupt.c | 2 +-
 fs/eventfd.c | 9 +
 include/linux/eventfd.h  | 9 -
 io_uring/io_uring.c  | 4 ++--
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/interrupt.c 
b/drivers/gpu/drm/i915/gvt/interrupt.c
index 3d9e09c2add4..31aff6f733d4 100644
--- a/drivers/gpu/drm/i915/gvt/interrupt.c
+++ b/drivers/gpu/drm/i915/gvt/interrupt.c
@@ -435,7 +435,7 @@ static int inject_virtual_interrupt(struct intel_vgpu *vgpu)
 */
if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status))
return -ESRCH;
-   if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger) != 1)
+   if (vgpu->msi_trigger && !eventfd_signal(vgpu->msi_trigger))
return -EFAULT;
return 0;
 }
diff --git a/fs/eventfd.c b/fs/eventfd.c
index dc9e01053235..077be5da72bd 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -43,9 +43,10 @@ struct eventfd_ctx {
int id;
 };
 
-__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask)
+bool eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask)
 {
unsigned long flags;
+   __u64 n = 1;
 
/*
 * Deadlock or stack overflow issues can happen if we recurse here
@@ -68,7 +69,7 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, 
__poll_t mask)
current->in_eventfd = 0;
spin_unlock_irqrestore(>wqh.lock, flags);
 
-   return n;
+   return n == 1;
 }
 
 /**
@@ -82,9 +83,9 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, 
__poll_t mask)
  *
  * Returns the amount by which the counter was incremented.
  */
-__u64 eventfd_signal(struct eventfd_ctx *ctx)
+bool eventfd_signal(struct eventfd_ctx *ctx)
 {
-   return eventfd_signal_mask(ctx, 1, 0);
+   return eventfd_signal_mask(ctx, 0);
 }
 EXPORT_SYMBOL_GPL(eventfd_signal);
 
diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h
index 562089431551..0155ee25f7c8 100644
--- a/include/linux/eventfd.h
+++ b/include/linux/eventfd.h
@@ -35,8 +35,8 @@ void eventfd_ctx_put(struct eventfd_ctx *ctx);
 struct file *eventfd_fget(int fd);
 struct eventfd_ctx *eventfd_ctx_fdget(int fd);
 struct eventfd_ctx *eventfd_ctx_fileget(struct file *file);
-__u64 eventfd_signal(struct eventfd_ctx *ctx);
-__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask);
+bool eventfd_signal(struct eventfd_ctx *ctx);
+bool eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask);
 int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t 
*wait,
  __u64 *cnt);
 void eventfd_ctx_do_read(struct eventfd_ctx *ctx, __u64 *cnt);
@@ -58,13 +58,12 @@ static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd)
return ERR_PTR(-ENOSYS);
 }
 
-static inline int eventfd_signal(struct eventfd_ctx *ctx)
+static inline bool eventfd_signal(struct eventfd_ctx *ctx)
 {
return -ENOSYS;
 }
 
-static inline int eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n,
- unsigned mask)
+static inline bool eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned mask)
 {
return -ENOSYS;
 }
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index e8096d502a7c..a9359ef73935 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -537,7 +537,7 @@ static void io_eventfd_ops(struct rcu_head *rcu)
int ops = atomic_xchg(_fd->ops, 0);
 
if (ops & BIT(IO_EVENTFD_OP_SIGNAL_BIT))
-   eventfd_signal_mask(ev_fd->cq_ev_fd, 1, EPOLL_URING_WAKE);
+   eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
 
/* IO_EVENTFD_OP_FREE_BIT may not be set here depending on callback
 * ordering in a race but if references are 0 we know we have to free
@@ -573,7 +573,7 @@ static void io_eventfd_signal(struct io_ring_ctx *ctx)
goto out;
 
if (likely(eventfd_signal_allowed())) {
-   eventfd_signal_mask(ev_fd->cq_ev_fd, 1, EPOLL_URING_WAKE);
+   eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
} else {
atomic_inc(_fd->refs);
if (!atomic_fetch_or(BIT(IO_EVENTFD_OP_SIGNAL_BIT), 
_fd->ops))

-- 
2.34.1



[PATCH 1/2] eventfd: simplify eventfd_signal()

2023-07-13 Thread Christian Brauner
Ever since the evenfd type was introduced back in 2007 in commit
e1ad7468c77d ("signal/timer/event: eventfd core") the eventfd_signal()
function only ever passed 1 as a value for @n. There's no point in
keeping that additional argument.

Signed-off-by: Christian Brauner 
---
 arch/x86/kvm/hyperv.c |  2 +-
 arch/x86/kvm/xen.c|  2 +-
 drivers/accel/habanalabs/common/device.c  |  2 +-
 drivers/fpga/dfl.c|  2 +-
 drivers/gpu/drm/i915/gvt/interrupt.c  |  2 +-
 drivers/infiniband/hw/mlx5/devx.c |  2 +-
 drivers/misc/ocxl/file.c  |  2 +-
 drivers/s390/cio/vfio_ccw_chp.c   |  2 +-
 drivers/s390/cio/vfio_ccw_drv.c   |  4 ++--
 drivers/s390/cio/vfio_ccw_ops.c   |  6 +++---
 drivers/s390/crypto/vfio_ap_ops.c |  2 +-
 drivers/usb/gadget/function/f_fs.c|  4 ++--
 drivers/vdpa/vdpa_user/vduse_dev.c|  6 +++---
 drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c|  2 +-
 drivers/vfio/pci/vfio_pci_core.c  |  6 +++---
 drivers/vfio/pci/vfio_pci_intrs.c | 12 ++--
 drivers/vfio/platform/vfio_platform_irq.c |  4 ++--
 drivers/vhost/vdpa.c  |  4 ++--
 drivers/vhost/vhost.c | 10 +-
 drivers/vhost/vhost.h |  2 +-
 drivers/virt/acrn/ioeventfd.c |  2 +-
 fs/aio.c  |  2 +-
 fs/eventfd.c  |  9 +++--
 include/linux/eventfd.h   |  4 ++--
 mm/memcontrol.c   | 10 +-
 mm/vmpressure.c   |  2 +-
 samples/vfio-mdev/mtty.c  |  4 ++--
 virt/kvm/eventfd.c|  4 ++--
 28 files changed, 56 insertions(+), 59 deletions(-)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index b28fd020066f..2f4bd74b482c 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -2387,7 +2387,7 @@ static u16 kvm_hvcall_signal_event(struct kvm_vcpu *vcpu, 
struct kvm_hv_hcall *h
if (!eventfd)
return HV_STATUS_INVALID_PORT_ID;
 
-   eventfd_signal(eventfd, 1);
+   eventfd_signal(eventfd);
return HV_STATUS_SUCCESS;
 }
 
diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
index 40edf4d1974c..a7b62bafd57b 100644
--- a/arch/x86/kvm/xen.c
+++ b/arch/x86/kvm/xen.c
@@ -2043,7 +2043,7 @@ static bool kvm_xen_hcall_evtchn_send(struct kvm_vcpu 
*vcpu, u64 param, u64 *r)
if (ret < 0 && ret != -ENOTCONN)
return false;
} else {
-   eventfd_signal(evtchnfd->deliver.eventfd.ctx, 1);
+   eventfd_signal(evtchnfd->deliver.eventfd.ctx);
}
 
*r = 0;
diff --git a/drivers/accel/habanalabs/common/device.c 
b/drivers/accel/habanalabs/common/device.c
index b97339d1f7c6..30357b371d61 100644
--- a/drivers/accel/habanalabs/common/device.c
+++ b/drivers/accel/habanalabs/common/device.c
@@ -1963,7 +1963,7 @@ static void hl_notifier_event_send(struct 
hl_notifier_event *notifier_event, u64
notifier_event->events_mask |= event_mask;
 
if (notifier_event->eventfd)
-   eventfd_signal(notifier_event->eventfd, 1);
+   eventfd_signal(notifier_event->eventfd);
 
mutex_unlock(_event->lock);
 }
diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index dd7a783d53b5..e73f88050f08 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -1872,7 +1872,7 @@ static irqreturn_t dfl_irq_handler(int irq, void *arg)
 {
struct eventfd_ctx *trigger = arg;
 
-   eventfd_signal(trigger, 1);
+   eventfd_signal(trigger);
return IRQ_HANDLED;
 }
 
diff --git a/drivers/gpu/drm/i915/gvt/interrupt.c 
b/drivers/gpu/drm/i915/gvt/interrupt.c
index 68eca023bbc6..3d9e09c2add4 100644
--- a/drivers/gpu/drm/i915/gvt/interrupt.c
+++ b/drivers/gpu/drm/i915/gvt/interrupt.c
@@ -435,7 +435,7 @@ static int inject_virtual_interrupt(struct intel_vgpu *vgpu)
 */
if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status))
return -ESRCH;
-   if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger, 1) != 1)
+   if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger) != 1)
return -EFAULT;
return 0;
 }
diff --git a/drivers/infiniband/hw/mlx5/devx.c 
b/drivers/infiniband/hw/mlx5/devx.c
index db5fb196c728..ad50487790ff 100644
--- a/drivers/infiniband/hw/mlx5/devx.c
+++ b/drivers/infiniband/hw/mlx5/devx.c
@@ -2498,7 +2498,7 @@ static void dispatch_event_fd(struct list_head *fd_list,
 
list_for_each_entry_rcu(item, fd_list, xa_list) {
if (item->eventfd)
-   eventfd_signal(item->eventfd, 1);
+   eventfd_signal(item->eventfd);
else
deliver_event(item, data);
}
diff --git a/drivers/misc/ocxl/file.c b/drivers/misc/ocxl/file.c
index 6e63f060e4cc..51766db296ab 

[PATCH 0/2] eventfd: simplify signal helpers

2023-07-13 Thread Christian Brauner
Hey everyone,

This simplifies the eventfd_signal() and eventfd_signal_mask() helpers
by removing the count argument which is effectively unused.

---



---
base-commit: 6be357f00aad4189130147fdc6f568cf776a4909
change-id: 20230713-vfs-eventfd-signal-0b0d167ad6ec



Re: [PATCH rfc -next 01/10] mm: add a generic VMA lock-based page fault handler

2023-07-13 Thread Suren Baghdasaryan
On Thu, Jul 13, 2023 at 9:15 AM Matthew Wilcox  wrote:
>
> > +int try_vma_locked_page_fault(struct vm_locked_fault *vmlf, vm_fault_t 
> > *ret)
> > +{
> > + struct vm_area_struct *vma;
> > + vm_fault_t fault;
>
>
> On Thu, Jul 13, 2023 at 05:53:29PM +0800, Kefeng Wang wrote:
> > +#define VM_LOCKED_FAULT_INIT(_name, _mm, _address, _fault_flags, 
> > _vm_flags, _regs, _fault_code) \
> > + _name.mm= _mm;  \
> > + _name.address   = _address; \
> > + _name.fault_flags   = _fault_flags; \
> > + _name.vm_flags  = _vm_flags;\
> > + _name.regs  = _regs;\
> > + _name.fault_code= _fault_code
>
> More consolidated code is a good idea; no question.  But I don't think
> this is the right way to do it.
>
> > +int __weak arch_vma_check_access(struct vm_area_struct *vma,
> > +  struct vm_locked_fault *vmlf);
>
> This should be:
>
> #ifndef vma_check_access
> bool vma_check_access(struct vm_area_struct *vma, )
> {
> return (vma->vm_flags & vm_flags) == 0;
> }
> #endif
>
> and then arches which want to do something different can just define
> vma_check_access.
>
> > +int try_vma_locked_page_fault(struct vm_locked_fault *vmlf, vm_fault_t 
> > *ret)
> > +{
> > + struct vm_area_struct *vma;
> > + vm_fault_t fault;
>
> Declaring the vmf in this function and then copying it back is just wrong.
> We need to declare vm_fault_t earlier (in the arch fault handler) and
> pass it in.

Did you mean to say "we need to declare vmf (struct vm_fault) earlier
(in the arch fault handler) and pass it in." ?

>  I don't think that creating struct vm_locked_fault is the
> right idea either.
>
> > + if (!(vmlf->fault_flags & FAULT_FLAG_USER))
> > + return -EINVAL;
> > +
> > + vma = lock_vma_under_rcu(vmlf->mm, vmlf->address);
> > + if (!vma)
> > + return -EINVAL;
> > +
> > + if (arch_vma_check_access(vma, vmlf)) {
> > + vma_end_read(vma);
> > + return -EINVAL;
> > + }
> > +
> > + fault = handle_mm_fault(vma, vmlf->address,
> > + vmlf->fault_flags | FAULT_FLAG_VMA_LOCK,
> > + vmlf->regs);
> > + *ret = fault;
> > +
> > + if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
> > + vma_end_read(vma);
> > +
> > + if ((fault & VM_FAULT_RETRY))
> > + count_vm_vma_lock_event(VMA_LOCK_RETRY);
> > + else
> > + count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
> > +
> > + return 0;
> > +}
> > +
> >  #endif /* CONFIG_PER_VMA_LOCK */
> >
> >  #ifndef __PAGETABLE_P4D_FOLDED
> > --
> > 2.27.0
> >
> >


Re: [PATCH 1/2] tools/perf/tests: perf all metrics test fails when perf_event access is restricted

2023-07-13 Thread Athira Rajeev



> On 05-Jul-2023, at 11:54 PM, Namhyung Kim  wrote:
> 
> On Mon, Jul 3, 2023 at 10:04 PM Athira Rajeev
>  wrote:
>> 
>> 
>> 
>>> On 15-Jun-2023, at 1:08 PM, Athira Rajeev  
>>> wrote:
>>> 
>>> Perf all metrics test fails as below when perf_event access
>>> is restricted.
>>> 
>>>   ./perf test -v "perf all metrics test"
>>>   Metric 'Memory_RD_BW_Chip' not printed in:
>>>   Error:
>>>   Access to performance monitoring and observability operations is limited.
>>>   Enforced MAC policy settings (SELinux) can limit access to performance
>>>   —
>>>   access to performance monitoring and observability operations for 
>>> processes
>>>   without CAP_PERFMON, CAP_SYS_PTRACE or CAP_SYS_ADMIN Linux capability.
>>>   —
>>>   test child finished with -1
>>>    end 
>>>   perf all metrics test: FAILED!
> 
> In my system, it fails like below:
> 
>  $ ./perf test -v 101
>  101: perf all metrics test   :
>  --- start ---
>  test child forked, pid 398458
>  Testing branch_misprediction_ratio
>  Testing all_remote_links_outbound
>  Metric 'all_remote_links_outbound' not printed in:
>  Error:
>  Invalid event (remote_outbound_data_controller_3:u) in per-thread
> mode, enable system wide with '-a'.
>  Testing nps1_die_to_dram

Hi Namhyung,

Thanks for checking. Is the fail behaviour observed after applying this fix 
patch ?
I will check it in my setup 

Athira
>  ...
> 
> Thanks,
> Namhyung
> 
>> 
>> 
>> Hi,
>> 
>> Looking for review comments on this patch.
>> 
>> Thanks
>>> 
>>> The perf all metrics test picks the input events from
>>> "perf list --raw-dump metrics" and runs "perf stat -M "$m""
>>> for each of the metrics in the list. It fails here for some
>>> of the metrics which needs access, since it collects system
>>> wide resource details/statistics. Fix the testcase to skip
>>> those metric events.
>>> 
>>> Signed-off-by: Athira Rajeev 
>>> ---
>>> tools/perf/tests/shell/stat_all_metrics.sh | 4 +++-
>>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>> 
>>> diff --git a/tools/perf/tests/shell/stat_all_metrics.sh 
>>> b/tools/perf/tests/shell/stat_all_metrics.sh
>>> index 54774525e18a..14b96484a359 100755
>>> --- a/tools/perf/tests/shell/stat_all_metrics.sh
>>> +++ b/tools/perf/tests/shell/stat_all_metrics.sh
>>> @@ -6,7 +6,9 @@ err=0
>>> for m in $(perf list --raw-dump metrics); do
>>>  echo "Testing $m"
>>>  result=$(perf stat -M "$m" true 2>&1)
>>> -  if [[ "$result" =~ ${m:0:50} ]] || [[ "$result" =~ "" ]]
>>> +  # Skip if there is no access to perf_events monitoring
>>> +  # and observability operations
>>> +  if [[ "$result" =~ ${m:0:50} ]] || [[ "$result" =~ "" ]] 
>>> || [[ "$result" =~ "Access to performance monitoring and observability 
>>> operations is limited" ]]
>>>  then
>>>continue
>>>  fi
>>> --
>>> 2.31.1




Re: [PATCH 0/2] PCI/AER: Remove/unexport error reporting enable/disable

2023-07-13 Thread Bjorn Helgaas
On Mon, Jul 10, 2023 at 06:21:34PM -0500, Bjorn Helgaas wrote:
> From: Bjorn Helgaas 
> 
> pci_disable_pcie_error_reporting() is unused; remove it.
> pci_enable_pcie_error_reporting() is used only inside aer.c; make it
> static.
> 
> Bjorn Helgaas (2):
>   PCI/AER: Drop unused pci_disable_pcie_error_reporting()
>   PCI/AER: Unexport pci_enable_pcie_error_reporting()
> 
>  drivers/pci/pcie/aer.c | 15 +--
>  include/linux/aer.h| 11 ---
>  2 files changed, 1 insertion(+), 25 deletions(-)

Applied to pci/aer for v6.6, thanks Christoph and Sathy!


Re: [PATCH rfc -next 01/10] mm: add a generic VMA lock-based page fault handler

2023-07-13 Thread Matthew Wilcox
> +int try_vma_locked_page_fault(struct vm_locked_fault *vmlf, vm_fault_t *ret)
> +{
> + struct vm_area_struct *vma;
> + vm_fault_t fault;


On Thu, Jul 13, 2023 at 05:53:29PM +0800, Kefeng Wang wrote:
> +#define VM_LOCKED_FAULT_INIT(_name, _mm, _address, _fault_flags, _vm_flags, 
> _regs, _fault_code) \
> + _name.mm= _mm;  \
> + _name.address   = _address; \
> + _name.fault_flags   = _fault_flags; \
> + _name.vm_flags  = _vm_flags;\
> + _name.regs  = _regs;\
> + _name.fault_code= _fault_code

More consolidated code is a good idea; no question.  But I don't think
this is the right way to do it.

> +int __weak arch_vma_check_access(struct vm_area_struct *vma,
> +  struct vm_locked_fault *vmlf);

This should be:

#ifndef vma_check_access
bool vma_check_access(struct vm_area_struct *vma, )
{
return (vma->vm_flags & vm_flags) == 0;
}
#endif

and then arches which want to do something different can just define
vma_check_access.

> +int try_vma_locked_page_fault(struct vm_locked_fault *vmlf, vm_fault_t *ret)
> +{
> + struct vm_area_struct *vma;
> + vm_fault_t fault;

Declaring the vmf in this function and then copying it back is just wrong.
We need to declare vm_fault_t earlier (in the arch fault handler) and
pass it in.  I don't think that creating struct vm_locked_fault is the
right idea either.

> + if (!(vmlf->fault_flags & FAULT_FLAG_USER))
> + return -EINVAL;
> +
> + vma = lock_vma_under_rcu(vmlf->mm, vmlf->address);
> + if (!vma)
> + return -EINVAL;
> +
> + if (arch_vma_check_access(vma, vmlf)) {
> + vma_end_read(vma);
> + return -EINVAL;
> + }
> +
> + fault = handle_mm_fault(vma, vmlf->address,
> + vmlf->fault_flags | FAULT_FLAG_VMA_LOCK,
> + vmlf->regs);
> + *ret = fault;
> +
> + if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
> + vma_end_read(vma);
> +
> + if ((fault & VM_FAULT_RETRY))
> + count_vm_vma_lock_event(VMA_LOCK_RETRY);
> + else
> + count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
> +
> + return 0;
> +}
> +
>  #endif /* CONFIG_PER_VMA_LOCK */
>  
>  #ifndef __PAGETABLE_P4D_FOLDED
> -- 
> 2.27.0
> 
> 


Re: linux-next: Tree for Jul 13 (drivers/video/fbdev/ps3fb.c)

2023-07-13 Thread Randy Dunlap


On 7/12/23 19:37, Stephen Rothwell wrote:
> Hi all,
> 
> Changes since 20230712:
> 

on ppc64:

In file included from ../include/linux/device.h:15,
 from ../arch/powerpc/include/asm/io.h:22,
 from ../include/linux/io.h:13,
 from ../include/linux/irq.h:20,
 from ../arch/powerpc/include/asm/hardirq.h:6,
 from ../include/linux/hardirq.h:11,
 from ../include/linux/interrupt.h:11,
 from ../drivers/video/fbdev/ps3fb.c:25:
../drivers/video/fbdev/ps3fb.c: In function 'ps3fb_probe':
../drivers/video/fbdev/ps3fb.c:1172:40: error: 'struct fb_info' has no member 
named 'dev'
 1172 |  dev_driver_string(info->dev), dev_name(info->dev),
  |^~
../include/linux/dev_printk.h:110:37: note: in definition of macro 
'dev_printk_index_wrap'
  110 | _p_func(dev, fmt, ##__VA_ARGS__);   
\
  | ^~~
../drivers/video/fbdev/ps3fb.c:1171:9: note: in expansion of macro 'dev_info'
 1171 | dev_info(info->device, "%s %s, using %u KiB of video memory\n",
  | ^~~~
../drivers/video/fbdev/ps3fb.c:1172:61: error: 'struct fb_info' has no member 
named 'dev'
 1172 |  dev_driver_string(info->dev), dev_name(info->dev),
  | ^~
../include/linux/dev_printk.h:110:37: note: in definition of macro 
'dev_printk_index_wrap'
  110 | _p_func(dev, fmt, ##__VA_ARGS__);   
\
  | ^~~
../drivers/video/fbdev/ps3fb.c:1171:9: note: in expansion of macro 'dev_info'
 1171 | dev_info(info->device, "%s %s, using %u KiB of video memory\n",
  | ^~~~


Full randconfig file is attached.
-- 
~Randy

config-r3073.gz
Description: application/gzip


Re: [PATCH v2 18/18] fbdev: Document that framebuffer_alloc() returns zero'ed data

2023-07-13 Thread Randy Dunlap



On 7/13/23 06:21, Miguel Ojeda wrote:
> On Thu, Jul 13, 2023 at 3:03 PM Thomas Zimmermann  wrote:
>>
>> Most fbdev drivers depend on framebuffer_alloc() to initialize the
>> allocated memory to 0. Document this guarantee.
>>
>> Suggested-by: Miguel Ojeda 
>> Signed-off-by: Thomas Zimmermann 
>> Cc: Helge Deller 
> 
> Thanks for sending this! Maybe this would be best earlier in the
> series, so that later patches make more sense (since they use the
> guarantee), but it is not a big deal.
> 
>> + * aligned to sizeof(long). Both, the instance of struct fb_info and
>> + * the driver private data, are cleared to zero.
> 
> I think both commas may be best omitted (but I am not a native speaker).

Yes, it would be better to omit them.

> Reviewed-by: Miguel Ojeda 
> 
> Cheers,
> Miguel

-- 
~Randy


Re: [PATCH v2 08/18] sh: Assign FB_MODE_IS_UNKNOWN to struct fb_videomode.flag

2023-07-13 Thread John Paul Adrian Glaubitz
Hi Thomas!

On Thu, 2023-07-13 at 15:53 +0200, John Paul Adrian Glaubitz wrote:
> On Thu, 2023-07-13 at 14:58 +0200, Thomas Zimmermann wrote:
> > Assign FB_MODE_IS_UNKNOWN to sh7763fb_videomode.flag instead of
> > FBINFO_FLAG_DEFAULT. Both are 0, so the stored value does not change.
> > 
> > FBINFO_FLAG_DEFAULT is a flag for a framebuffer in struct fb_info.
> > Flags for videomodes are prefixed with FB_MODE_.
> > 
> > v2:
> > * assign FB_MODE_IS_UNKNOWN (Adrian)
> > 
> > Signed-off-by: Thomas Zimmermann 
> > Acked-by: Sam Ravnborg 
> > Cc: Yoshinori Sato 
> > Cc: Rich Felker 
> > Cc: John Paul Adrian Glaubitz 
> > ---
> >  arch/sh/boards/mach-sh7763rdp/setup.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/sh/boards/mach-sh7763rdp/setup.c 
> > b/arch/sh/boards/mach-sh7763rdp/setup.c
> > index 97e715e4e9b3..e25193001ea0 100644
> > --- a/arch/sh/boards/mach-sh7763rdp/setup.c
> > +++ b/arch/sh/boards/mach-sh7763rdp/setup.c
> > @@ -119,7 +119,7 @@ static struct fb_videomode sh7763fb_videomode = {
> > .vsync_len = 1,
> > .sync = 0,
> > .vmode = FB_VMODE_NONINTERLACED,
> > -   .flag = FBINFO_FLAG_DEFAULT,
> > +   .flag = FB_MODE_IS_UNKNOWN,
> >  };
> >  
> >  static struct sh7760fb_platdata sh7763fb_def_pdata = {
> 
> Acked-by: John Paul Adrian Glaubitz 

Ah, just one tiny request: Could you change the subject to include the
board name, i.e.:

sh: mach-sh7763rdp: Assign FB_MODE_IS_UNKNOWN to struct 
fb_videomode.flag

?

I wasn't paying close attention to the path of the file being changed when
I first looked at your patch. Sorry for that.

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913


Re: [PATCH v2 08/18] sh: Assign FB_MODE_IS_UNKNOWN to struct fb_videomode.flag

2023-07-13 Thread John Paul Adrian Glaubitz
On Thu, 2023-07-13 at 14:58 +0200, Thomas Zimmermann wrote:
> Assign FB_MODE_IS_UNKNOWN to sh7763fb_videomode.flag instead of
> FBINFO_FLAG_DEFAULT. Both are 0, so the stored value does not change.
> 
> FBINFO_FLAG_DEFAULT is a flag for a framebuffer in struct fb_info.
> Flags for videomodes are prefixed with FB_MODE_.
> 
> v2:
>   * assign FB_MODE_IS_UNKNOWN (Adrian)
> 
> Signed-off-by: Thomas Zimmermann 
> Acked-by: Sam Ravnborg 
> Cc: Yoshinori Sato 
> Cc: Rich Felker 
> Cc: John Paul Adrian Glaubitz 
> ---
>  arch/sh/boards/mach-sh7763rdp/setup.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/sh/boards/mach-sh7763rdp/setup.c 
> b/arch/sh/boards/mach-sh7763rdp/setup.c
> index 97e715e4e9b3..e25193001ea0 100644
> --- a/arch/sh/boards/mach-sh7763rdp/setup.c
> +++ b/arch/sh/boards/mach-sh7763rdp/setup.c
> @@ -119,7 +119,7 @@ static struct fb_videomode sh7763fb_videomode = {
>   .vsync_len = 1,
>   .sync = 0,
>   .vmode = FB_VMODE_NONINTERLACED,
> - .flag = FBINFO_FLAG_DEFAULT,
> + .flag = FB_MODE_IS_UNKNOWN,
>  };
>  
>  static struct sh7760fb_platdata sh7763fb_def_pdata = {

Acked-by: John Paul Adrian Glaubitz 

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913


Re: [PATCH v2 18/18] fbdev: Document that framebuffer_alloc() returns zero'ed data

2023-07-13 Thread Miguel Ojeda
On Thu, Jul 13, 2023 at 3:03 PM Thomas Zimmermann  wrote:
>
> Most fbdev drivers depend on framebuffer_alloc() to initialize the
> allocated memory to 0. Document this guarantee.
>
> Suggested-by: Miguel Ojeda 
> Signed-off-by: Thomas Zimmermann 
> Cc: Helge Deller 

Thanks for sending this! Maybe this would be best earlier in the
series, so that later patches make more sense (since they use the
guarantee), but it is not a big deal.

> + * aligned to sizeof(long). Both, the instance of struct fb_info and
> + * the driver private data, are cleared to zero.

I think both commas may be best omitted (but I am not a native speaker).

Reviewed-by: Miguel Ojeda 

Cheers,
Miguel


[PATCH v2 18/18] fbdev: Document that framebuffer_alloc() returns zero'ed data

2023-07-13 Thread Thomas Zimmermann
Most fbdev drivers depend on framebuffer_alloc() to initialize the
allocated memory to 0. Document this guarantee.

Suggested-by: Miguel Ojeda 
Signed-off-by: Thomas Zimmermann 
Cc: Helge Deller 
---
 drivers/video/fbdev/core/fb_info.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/core/fb_info.c 
b/drivers/video/fbdev/core/fb_info.c
index 8bdbefdd4b70..1b7615fc393d 100644
--- a/drivers/video/fbdev/core/fb_info.c
+++ b/drivers/video/fbdev/core/fb_info.c
@@ -13,7 +13,8 @@
  *
  * Creates a new frame buffer info structure. Also reserves @size bytes
  * for driver private data (info->par). info->par (if any) will be
- * aligned to sizeof(long).
+ * aligned to sizeof(long). Both, the instance of struct fb_info and
+ * the driver private data, are cleared to zero.
  *
  * Returns the new structure, or NULL if an error occurred.
  *
-- 
2.41.0



[PATCH v2 17/18] fbdev: Remove FBINFO_DEFAULT and FBINFO_FLAG_DEFAULT

2023-07-13 Thread Thomas Zimmermann
Remove the unused flags FBINFO_DEFAULT and FBINFO_FLAG_DEFAULT. No
functional changes.

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Cc: Helge Deller 
---
 include/linux/fb.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/linux/fb.h b/include/linux/fb.h
index 1d5c13f34b09..43458f582f35 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -383,7 +383,6 @@ struct fb_tile_ops {
 #endif /* CONFIG_FB_TILEBLITTING */
 
 /* FBINFO_* = fb_info.flags bit flags */
-#define FBINFO_DEFAULT 0
 #define FBINFO_HWACCEL_DISABLED0x0002
/* When FBINFO_HWACCEL_DISABLED is set:
 *  Hardware acceleration is turned off.  Software implementations
@@ -504,8 +503,6 @@ struct fb_info {
bool skip_vt_switch; /* no VT switch on suspend/resume required */
 };
 
-#define FBINFO_FLAG_DEFAULTFBINFO_DEFAULT
-
 /* This will go away
  * fbset currently hacks in FB_ACCELF_TEXT into var.accel_flags
  * when it wants to turn the acceleration engine on.  This is
-- 
2.41.0



[PATCH v2 16/18] fbdev/pxafb: Remove flag FBINFO_FLAG_DEFAULT

2023-07-13 Thread Thomas Zimmermann
The flag FBINFO_FLAG_DEFAULT is 0 and has no effect, as struct
fbinfo.flags has been allocated to zero by devm_kzalloc(). So do not
set it.

Flags should signal differences from the default values. After cleaning
up all occurrences of FBINFO_DEFAULT, the token will be removed.

v2:
* fix commit message (Miguel)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Cc: Helge Deller 
---
 drivers/video/fbdev/pxafb.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/video/fbdev/pxafb.c b/drivers/video/fbdev/pxafb.c
index c8c4677d06b4..beffb0602a2c 100644
--- a/drivers/video/fbdev/pxafb.c
+++ b/drivers/video/fbdev/pxafb.c
@@ -888,7 +888,6 @@ static void init_pxafb_overlay(struct pxafb_info *fbi, 
struct pxafb_layer *ofb,
ofb->fb.var.vmode   = FB_VMODE_NONINTERLACED;
 
ofb->fb.fbops   = _fb_ops;
-   ofb->fb.flags   = FBINFO_FLAG_DEFAULT;
ofb->fb.node= -1;
ofb->fb.pseudo_palette  = NULL;
 
-- 
2.41.0



[PATCH v2 14/18] fbdev: Remove flag FBINFO_FLAG_DEFAULT from fbdev drivers

2023-07-13 Thread Thomas Zimmermann
The flag FBINFO_FLAG_DEFAULT is 0 and has no effect, as struct
fbinfo.flags has been allocated to zero by framebuffer_alloc(). So
do not set it.

Flags should signal differences from the default values. After cleaning
up all occurrences of FBINFO_DEFAULT, the token will be removed.

v2:
* fix commit message (Miguel)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Cc: Jaya Kumar 
Cc: Helge Deller 
Cc: Peter Jones 
Cc: Sascha Hauer 
Cc: Pengutronix Kernel Team 
Cc: Shawn Guo 
Cc: Fabio Estevam 
Cc: NXP Linux Team 
Cc: Maik Broemme 
Cc: Jingoo Han 
Cc: Sudip Mukherjee 
Cc: Teddy Wang 
Cc: Michal Januszewski 
---
 drivers/video/fbdev/arcfb.c| 1 -
 drivers/video/fbdev/aty/aty128fb.c | 1 -
 drivers/video/fbdev/broadsheetfb.c | 2 +-
 drivers/video/fbdev/da8xx-fb.c | 1 -
 drivers/video/fbdev/efifb.c| 1 -
 drivers/video/fbdev/goldfishfb.c   | 1 -
 drivers/video/fbdev/gxt4500.c  | 3 +--
 drivers/video/fbdev/hecubafb.c | 2 +-
 drivers/video/fbdev/imxfb.c| 3 +--
 drivers/video/fbdev/intelfb/intelfbdrv.c   | 1 -
 drivers/video/fbdev/metronomefb.c  | 2 +-
 drivers/video/fbdev/mx3fb.c| 1 -
 drivers/video/fbdev/omap/omapfb_main.c | 1 -
 drivers/video/fbdev/omap2/omapfb/omapfb-main.c | 1 -
 drivers/video/fbdev/s3c-fb.c   | 1 -
 drivers/video/fbdev/sh_mobile_lcdcfb.c | 2 --
 drivers/video/fbdev/sis/sis_main.c | 2 --
 drivers/video/fbdev/sm501fb.c  | 2 +-
 drivers/video/fbdev/sm712fb.c  | 1 -
 drivers/video/fbdev/uvesafb.c  | 3 +--
 drivers/video/fbdev/vesafb.c   | 2 +-
 drivers/video/fbdev/vfb.c  | 1 -
 drivers/video/fbdev/vga16fb.c  | 2 +-
 drivers/video/fbdev/xen-fbfront.c  | 2 +-
 24 files changed, 10 insertions(+), 29 deletions(-)

diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
index 9aaea3be8281..cff11cb04a55 100644
--- a/drivers/video/fbdev/arcfb.c
+++ b/drivers/video/fbdev/arcfb.c
@@ -546,7 +546,6 @@ static int arcfb_probe(struct platform_device *dev)
par->c2io_addr = c2io_addr;
par->cslut[0] = 0x00;
par->cslut[1] = 0x06;
-   info->flags = FBINFO_FLAG_DEFAULT;
spin_lock_init(>lock);
if (irq) {
par->irq = irq;
diff --git a/drivers/video/fbdev/aty/aty128fb.c 
b/drivers/video/fbdev/aty/aty128fb.c
index 2d9320a52e51..b44fc78ccd4f 100644
--- a/drivers/video/fbdev/aty/aty128fb.c
+++ b/drivers/video/fbdev/aty/aty128fb.c
@@ -1927,7 +1927,6 @@ static int aty128_init(struct pci_dev *pdev, const struct 
pci_device_id *ent)
 
/* fill in info */
info->fbops = _ops;
-   info->flags = FBINFO_FLAG_DEFAULT;
 
par->lcd_on = default_lcd_on;
par->crt_on = default_crt_on;
diff --git a/drivers/video/fbdev/broadsheetfb.c 
b/drivers/video/fbdev/broadsheetfb.c
index cb725a91b6bb..e51e14c29c55 100644
--- a/drivers/video/fbdev/broadsheetfb.c
+++ b/drivers/video/fbdev/broadsheetfb.c
@@ -1069,7 +1069,7 @@ static int broadsheetfb_probe(struct platform_device *dev)
 
mutex_init(>io_lock);
 
-   info->flags = FBINFO_FLAG_DEFAULT | FBINFO_VIRTFB;
+   info->flags = FBINFO_VIRTFB;
 
info->fbdefio = _defio;
fb_deferred_io_init(info);
diff --git a/drivers/video/fbdev/da8xx-fb.c b/drivers/video/fbdev/da8xx-fb.c
index 60cd1286370f..988dedcf6be8 100644
--- a/drivers/video/fbdev/da8xx-fb.c
+++ b/drivers/video/fbdev/da8xx-fb.c
@@ -1463,7 +1463,6 @@ static int fb_probe(struct platform_device *device)
da8xx_fb_var.bits_per_pixel = lcd_cfg->bpp;
 
/* Initialize fbinfo */
-   da8xx_fb_info->flags = FBINFO_FLAG_DEFAULT;
da8xx_fb_info->fix = da8xx_fb_fix;
da8xx_fb_info->var = da8xx_fb_var;
da8xx_fb_info->fbops = _fb_ops;
diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c
index 3d7be69ab593..3391c8e84210 100644
--- a/drivers/video/fbdev/efifb.c
+++ b/drivers/video/fbdev/efifb.c
@@ -555,7 +555,6 @@ static int efifb_probe(struct platform_device *dev)
info->fbops = _ops;
info->var = efifb_defined;
info->fix = efifb_fix;
-   info->flags = FBINFO_FLAG_DEFAULT;
 
orientation = drm_get_panel_orientation_quirk(efifb_defined.xres,
  efifb_defined.yres);
diff --git a/drivers/video/fbdev/goldfishfb.c b/drivers/video/fbdev/goldfishfb.c
index 6fa2108fd912..ef2528c3faa9 100644
--- a/drivers/video/fbdev/goldfishfb.c
+++ b/drivers/video/fbdev/goldfishfb.c
@@ -212,7 +212,6 @@ static int goldfish_fb_probe(struct platform_device *pdev)
height = readl(fb->reg_base + FB_GET_HEIGHT);
 
fb->fb.fbops= _fb_ops;
-   fb->fb.flags= FBINFO_FLAG_DEFAULT;
fb->fb.pseudo_palette   = fb->cmap;
   

[PATCH v2 15/18] fbdev/atafb: Remove flag FBINFO_FLAG_DEFAULT

2023-07-13 Thread Thomas Zimmermann
The flag FBINFO_FLAG_DEFAULT is 0 and has no effect, as struct
fbinfo.flags has been allocated to zero by a static declaration. So do
not set it.

Flags should signal differences from the default values. After cleaning
up all occurrences of FBINFO_DEFAULT, the token will be removed.

v2:
* fix commit message (Miguel)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Cc: Helge Deller 
---
 drivers/video/fbdev/atafb.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/video/fbdev/atafb.c b/drivers/video/fbdev/atafb.c
index 2bc4089865e6..c4a420b791b9 100644
--- a/drivers/video/fbdev/atafb.c
+++ b/drivers/video/fbdev/atafb.c
@@ -3112,7 +3112,6 @@ static int __init atafb_probe(struct platform_device 
*pdev)
 #ifdef ATAFB_FALCON
fb_info.pseudo_palette = current_par.hw.falcon.pseudo_palette;
 #endif
-   fb_info.flags = FBINFO_FLAG_DEFAULT;
 
if (!fb_find_mode(_info.var, _info, mode_option, atafb_modedb,
  NUM_TOTAL_MODES, _modedb[defmode],
-- 
2.41.0



[PATCH v2 13/18] fbdev: Remove flag FBINFO_FLAG_DEFAULT from fbdev drivers

2023-07-13 Thread Thomas Zimmermann
The flag FBINFO_FLAG_DEFAULT is 0 and has no effect, as struct
fbinfo.flags has been allocated to zero by kzalloc(). So do not
set it.

Flags should signal differences from the default values. After cleaning
up all occurrences of FBINFO_DEFAULT, the token will be removed.

v2:
* fix commit message (Miguel)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Cc: Helge Deller 
---
 drivers/video/fbdev/amba-clcd.c | 1 -
 drivers/video/fbdev/matrox/matroxfb_crtc2.c | 5 ++---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/video/fbdev/amba-clcd.c b/drivers/video/fbdev/amba-clcd.c
index e45338227be6..24d89e6fb780 100644
--- a/drivers/video/fbdev/amba-clcd.c
+++ b/drivers/video/fbdev/amba-clcd.c
@@ -461,7 +461,6 @@ static int clcdfb_register(struct clcd_fb *fb)
}
 
fb->fb.fbops= _ops;
-   fb->fb.flags= FBINFO_FLAG_DEFAULT;
fb->fb.pseudo_palette   = fb->cmap;
 
strncpy(fb->fb.fix.id, clcd_name, sizeof(fb->fb.fix.id));
diff --git a/drivers/video/fbdev/matrox/matroxfb_crtc2.c 
b/drivers/video/fbdev/matrox/matroxfb_crtc2.c
index 7655afa3fd50..372197c124de 100644
--- a/drivers/video/fbdev/matrox/matroxfb_crtc2.c
+++ b/drivers/video/fbdev/matrox/matroxfb_crtc2.c
@@ -603,9 +603,8 @@ static int matroxfb_dh_regit(const struct matrox_fb_info 
*minfo,
void* oldcrtc2;
 
m2info->fbcon.fbops = _dh_ops;
-   m2info->fbcon.flags = FBINFO_FLAG_DEFAULT;
-   m2info->fbcon.flags |= FBINFO_HWACCEL_XPAN |
-  FBINFO_HWACCEL_YPAN;
+   m2info->fbcon.flags = FBINFO_HWACCEL_XPAN |
+ FBINFO_HWACCEL_YPAN;
m2info->fbcon.pseudo_palette = m2info->cmap;
fb_alloc_cmap(>fbcon.cmap, 256, 1);
 
-- 
2.41.0



[PATCH v2 12/18] staging: Remove flag FBINFO_FLAG_DEFAULT from fbdev drivers

2023-07-13 Thread Thomas Zimmermann
The flag FBINFO_FLAG_DEFAULT is 0 and has no effect, as struct
fbinfo.flags has been allocated to zero by framebuffer_alloc(). So do
not set it.

Flags should signal differences from the default values. After cleaning
up all occurrences of FBINFO_DEFAULT, the token will be removed.

v2:
* fix commit message (Miguel)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Cc: Greg Kroah-Hartman 
Cc: Sudip Mukherjee 
Cc: Teddy Wang 
---
 drivers/staging/fbtft/fbtft-core.c | 2 +-
 drivers/staging/sm750fb/sm750.c| 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/fbtft/fbtft-core.c 
b/drivers/staging/fbtft/fbtft-core.c
index 3a4abf3bae40..eac1d570f437 100644
--- a/drivers/staging/fbtft/fbtft-core.c
+++ b/drivers/staging/fbtft/fbtft-core.c
@@ -684,7 +684,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct 
fbtft_display *display,
info->var.transp.offset =  0;
info->var.transp.length =  0;
 
-   info->flags =  FBINFO_FLAG_DEFAULT | FBINFO_VIRTFB;
+   info->flags =  FBINFO_VIRTFB;
 
par = info->par;
par->info = info;
diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c
index c260f73cf570..79bcd5bd4938 100644
--- a/drivers/staging/sm750fb/sm750.c
+++ b/drivers/staging/sm750fb/sm750.c
@@ -807,7 +807,6 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int 
index)
info->screen_base = crtc->v_screen;
pr_debug("screen_base vaddr = %p\n", info->screen_base);
info->screen_size = line_length * var->yres_virtual;
-   info->flags = FBINFO_FLAG_DEFAULT | 0;
 
/* set info->fix */
fix->type = FB_TYPE_PACKED_PIXELS;
-- 
2.41.0



[PATCH v2 11/18] media: Remove flag FBINFO_FLAG_DEFAULT from fbdev drivers

2023-07-13 Thread Thomas Zimmermann
The flag FBINFO_FLAG_DEFAULT is 0 and has no effect, as struct
fbinfo.flags has been allocated to zero by kzalloc(). So do not
set it.

Flags should signal differences from the default values. After cleaning
up all occurrences of FBINFO_DEFAULT, the token will be removed.

v2:
* fix commit message (Miguel)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Cc: Andy Walls 
Cc: Mauro Carvalho Chehab 
Cc: Hans Verkuil 
---
 drivers/media/pci/ivtv/ivtvfb.c  | 1 -
 drivers/media/test-drivers/vivid/vivid-osd.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/media/pci/ivtv/ivtvfb.c b/drivers/media/pci/ivtv/ivtvfb.c
index 0aeb9daaee4c..23c8c094e791 100644
--- a/drivers/media/pci/ivtv/ivtvfb.c
+++ b/drivers/media/pci/ivtv/ivtvfb.c
@@ -1048,7 +1048,6 @@ static int ivtvfb_init_vidmode(struct ivtv *itv)
/* Generate valid fb_info */
 
oi->ivtvfb_info.node = -1;
-   oi->ivtvfb_info.flags = FBINFO_FLAG_DEFAULT;
oi->ivtvfb_info.par = itv;
oi->ivtvfb_info.var = oi->ivtvfb_defined;
oi->ivtvfb_info.fix = oi->ivtvfb_fix;
diff --git a/drivers/media/test-drivers/vivid/vivid-osd.c 
b/drivers/media/test-drivers/vivid/vivid-osd.c
index ec25edc679b3..051f1805a16d 100644
--- a/drivers/media/test-drivers/vivid/vivid-osd.c
+++ b/drivers/media/test-drivers/vivid/vivid-osd.c
@@ -310,7 +310,6 @@ static int vivid_fb_init_vidmode(struct vivid_dev *dev)
/* Generate valid fb_info */
 
dev->fb_info.node = -1;
-   dev->fb_info.flags = FBINFO_FLAG_DEFAULT;
dev->fb_info.par = dev;
dev->fb_info.var = dev->fb_defined;
dev->fb_info.fix = dev->fb_fix;
-- 
2.41.0



[PATCH v2 09/18] auxdisplay: Remove flag FBINFO_FLAG_DEFAULT from fbdev drivers

2023-07-13 Thread Thomas Zimmermann
The flag FBINFO_FLAG_DEFAULT is 0 and has no effect, as struct
fbinfo.flags has been allocated to zero by framebuffer_alloc(). So do
not set it.

Flags should signal differences from the default values. After cleaning
up all occurrences of FBINFO_DEFAULT, the token will be removed.

v2:
* fix commit message (Miguel)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Acked-by: Miguel Ojeda 
Cc: Miguel Ojeda 
Cc: Robin van der Gracht 
---
 drivers/auxdisplay/cfag12864bfb.c | 1 -
 drivers/auxdisplay/ht16k33.c  | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/auxdisplay/cfag12864bfb.c 
b/drivers/auxdisplay/cfag12864bfb.c
index c2cab7e2b126..729845bcc803 100644
--- a/drivers/auxdisplay/cfag12864bfb.c
+++ b/drivers/auxdisplay/cfag12864bfb.c
@@ -79,7 +79,6 @@ static int cfag12864bfb_probe(struct platform_device *device)
info->var = cfag12864bfb_var;
info->pseudo_palette = NULL;
info->par = NULL;
-   info->flags = FBINFO_FLAG_DEFAULT;
 
if (register_framebuffer(info) < 0)
goto fballoced;
diff --git a/drivers/auxdisplay/ht16k33.c b/drivers/auxdisplay/ht16k33.c
index edaf92b7ea77..df3f37651e45 100644
--- a/drivers/auxdisplay/ht16k33.c
+++ b/drivers/auxdisplay/ht16k33.c
@@ -646,7 +646,6 @@ static int ht16k33_fbdev_probe(struct device *dev, struct 
ht16k33_priv *priv,
fbdev->info->var = ht16k33_fb_var;
fbdev->info->bl_dev = bl;
fbdev->info->pseudo_palette = NULL;
-   fbdev->info->flags = FBINFO_FLAG_DEFAULT;
fbdev->info->par = priv;
 
err = register_framebuffer(fbdev->info);
-- 
2.41.0



[PATCH v2 10/18] hid/picolcd: Remove flag FBINFO_FLAG_DEFAULT from fbdev driver

2023-07-13 Thread Thomas Zimmermann
The flag FBINFO_FLAG_DEFAULT is 0 and has no effect, as struct
fbinfo.flags has been allocated to zero by framebuffer_alloc(). So do
not set it.

Flags should signal differences from the default values. After cleaning
up all occurrences of FBINFO_DEFAULT, the token will be removed.

v2:
* fix commit message (Miguel)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Acked-by: Benjamin Tissoires 
Acked-by: Bruno Prémont 
Cc: "Bruno Prémont" 
Cc: Jiri Kosina 
Cc: Benjamin Tissoires 
---
 drivers/hid/hid-picolcd_fb.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/hid/hid-picolcd_fb.c b/drivers/hid/hid-picolcd_fb.c
index dabcd054dad9..d726aaafb146 100644
--- a/drivers/hid/hid-picolcd_fb.c
+++ b/drivers/hid/hid-picolcd_fb.c
@@ -527,7 +527,6 @@ int picolcd_init_framebuffer(struct picolcd_data *data)
info->var = picolcdfb_var;
info->fix = picolcdfb_fix;
info->fix.smem_len   = PICOLCDFB_SIZE*8;
-   info->flags = FBINFO_FLAG_DEFAULT;
 
fbdata = info->par;
spin_lock_init(>lock);
-- 
2.41.0



[PATCH v2 08/18] sh: Assign FB_MODE_IS_UNKNOWN to struct fb_videomode.flag

2023-07-13 Thread Thomas Zimmermann
Assign FB_MODE_IS_UNKNOWN to sh7763fb_videomode.flag instead of
FBINFO_FLAG_DEFAULT. Both are 0, so the stored value does not change.

FBINFO_FLAG_DEFAULT is a flag for a framebuffer in struct fb_info.
Flags for videomodes are prefixed with FB_MODE_.

v2:
* assign FB_MODE_IS_UNKNOWN (Adrian)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Cc: Yoshinori Sato 
Cc: Rich Felker 
Cc: John Paul Adrian Glaubitz 
---
 arch/sh/boards/mach-sh7763rdp/setup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sh/boards/mach-sh7763rdp/setup.c 
b/arch/sh/boards/mach-sh7763rdp/setup.c
index 97e715e4e9b3..e25193001ea0 100644
--- a/arch/sh/boards/mach-sh7763rdp/setup.c
+++ b/arch/sh/boards/mach-sh7763rdp/setup.c
@@ -119,7 +119,7 @@ static struct fb_videomode sh7763fb_videomode = {
.vsync_len = 1,
.sync = 0,
.vmode = FB_VMODE_NONINTERLACED,
-   .flag = FBINFO_FLAG_DEFAULT,
+   .flag = FB_MODE_IS_UNKNOWN,
 };
 
 static struct sh7760fb_platdata sh7763fb_def_pdata = {
-- 
2.41.0



[PATCH v2 07/18] vfio-mdev: Remove flag FBINFO_DEFAULT from fbdev sample driver

2023-07-13 Thread Thomas Zimmermann
The flag FBINFO_DEFAULT is 0 and has no effect, as struct fbinfo.flags
has been allocated to zero by framebuffer_alloc(). So do not set it.

Flags should signal differences from the default values. After cleaning
up all occurrences of FBINFO_DEFAULT, the token will be removed.

v2:
* fix commit message (Miguel)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Cc: Kirti Wankhede 
---
 samples/vfio-mdev/mdpy-fb.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/samples/vfio-mdev/mdpy-fb.c b/samples/vfio-mdev/mdpy-fb.c
index 3c8001b9e407..cda477b28685 100644
--- a/samples/vfio-mdev/mdpy-fb.c
+++ b/samples/vfio-mdev/mdpy-fb.c
@@ -162,7 +162,6 @@ static int mdpy_fb_probe(struct pci_dev *pdev,
}
 
info->fbops = _fb_ops;
-   info->flags = FBINFO_DEFAULT;
info->pseudo_palette = par->palette;
 
ret = register_framebuffer(info);
-- 
2.41.0



[PATCH v2 05/18] fbdev: Remove flag FBINFO_DEFAULT from fbdev drivers

2023-07-13 Thread Thomas Zimmermann
The flag FBINFO_DEFAULT is 0 and has no effect, as struct fbinfo.flags
has been allocated to zero by framebuffer_alloc(). So do not set it.

Flags should signal differences from the default values. After cleaning
up all occurrences of FBINFO_DEFAULT, the token will be removed.

v2:
* fix commit message (Miguel)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Cc: Helge Deller 
Cc: Nicolas Ferre 
Cc: Benjamin Herrenschmidt 
Cc: Ferenc Bakonyi 
Cc: "K. Y. Srinivasan" 
Cc: Haiyang Zhang 
Cc: Wei Liu 
Cc: Dexuan Cui 
Cc: Antonino Daplas 
Cc: Maik Broemme 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Christophe Leroy 
Cc: Kristoffer Ericson 
Cc: Hans de Goede 
Cc: Steve Glendinning 
Cc: Bernie Thompson 
Cc: Florian Tobias Schandinat 
---
 drivers/video/fbdev/amifb.c  | 5 ++---
 drivers/video/fbdev/asiliantfb.c | 1 -
 drivers/video/fbdev/atmel_lcdfb.c| 2 +-
 drivers/video/fbdev/aty/atyfb_base.c | 3 +--
 drivers/video/fbdev/aty/radeon_base.c| 3 +--
 drivers/video/fbdev/bw2.c| 1 -
 drivers/video/fbdev/carminefb.c  | 1 -
 drivers/video/fbdev/cg14.c   | 2 +-
 drivers/video/fbdev/cg3.c| 1 -
 drivers/video/fbdev/cg6.c| 2 +-
 drivers/video/fbdev/chipsfb.c| 1 -
 drivers/video/fbdev/cirrusfb.c   | 3 +--
 drivers/video/fbdev/clps711x-fb.c| 1 -
 drivers/video/fbdev/cobalt_lcdfb.c   | 1 -
 drivers/video/fbdev/ep93xx-fb.c  | 1 -
 drivers/video/fbdev/ffb.c| 3 +--
 drivers/video/fbdev/fm2fb.c  | 1 -
 drivers/video/fbdev/gbefb.c  | 1 -
 drivers/video/fbdev/geode/gx1fb_core.c   | 1 -
 drivers/video/fbdev/geode/gxfb_core.c| 1 -
 drivers/video/fbdev/geode/lxfb_core.c| 1 -
 drivers/video/fbdev/grvga.c  | 2 +-
 drivers/video/fbdev/hgafb.c  | 2 +-
 drivers/video/fbdev/hitfb.c  | 2 +-
 drivers/video/fbdev/hyperv_fb.c  | 2 --
 drivers/video/fbdev/i740fb.c | 2 +-
 drivers/video/fbdev/i810/i810_main.c | 4 ++--
 drivers/video/fbdev/imsttfb.c| 3 +--
 drivers/video/fbdev/intelfb/intelfbdrv.c | 4 ++--
 drivers/video/fbdev/kyro/fbdev.c | 1 -
 drivers/video/fbdev/leo.c| 1 -
 drivers/video/fbdev/mb862xx/mb862xxfbdrv.c   | 2 +-
 drivers/video/fbdev/mmp/fb/mmpfb.c   | 2 +-
 drivers/video/fbdev/neofb.c  | 2 +-
 drivers/video/fbdev/nvidia/nvidia.c  | 4 ++--
 drivers/video/fbdev/offb.c   | 2 +-
 drivers/video/fbdev/p9100.c  | 1 -
 drivers/video/fbdev/platinumfb.c | 1 -
 drivers/video/fbdev/pm2fb.c  | 3 +--
 drivers/video/fbdev/pm3fb.c  | 3 +--
 drivers/video/fbdev/pmag-aa-fb.c | 1 -
 drivers/video/fbdev/pmag-ba-fb.c | 1 -
 drivers/video/fbdev/pmagb-b-fb.c | 1 -
 drivers/video/fbdev/ps3fb.c  | 2 +-
 drivers/video/fbdev/pvr2fb.c | 2 +-
 drivers/video/fbdev/pxa168fb.c   | 2 +-
 drivers/video/fbdev/q40fb.c  | 1 -
 drivers/video/fbdev/riva/fbdev.c | 3 +--
 drivers/video/fbdev/s1d13xxxfb.c | 4 ++--
 drivers/video/fbdev/savage/savagefb_driver.c | 3 +--
 drivers/video/fbdev/simplefb.c   | 1 -
 drivers/video/fbdev/sis/sis_main.c   | 3 +--
 drivers/video/fbdev/skeletonfb.c | 2 +-
 drivers/video/fbdev/smscufx.c| 2 +-
 drivers/video/fbdev/sstfb.c  | 1 -
 drivers/video/fbdev/sunxvr1000.c | 1 -
 drivers/video/fbdev/sunxvr2500.c | 1 -
 drivers/video/fbdev/sunxvr500.c  | 1 -
 drivers/video/fbdev/tcx.c| 1 -
 drivers/video/fbdev/tdfxfb.c | 2 +-
 drivers/video/fbdev/tgafb.c  | 2 +-
 drivers/video/fbdev/tridentfb.c  | 2 +-
 drivers/video/fbdev/udlfb.c  | 2 +-
 drivers/video/fbdev/via/viafbdev.c   | 2 +-
 64 files changed, 41 insertions(+), 81 deletions(-)

diff --git a/drivers/video/fbdev/amifb.c b/drivers/video/fbdev/amifb.c
index d88265dbebf4..cea782283b9c 100644
--- a/drivers/video/fbdev/amifb.c
+++ b/drivers/video/fbdev/amifb.c
@@ -2427,7 +2427,7 @@ static int amifb_set_par(struct fb_info *info)
info->fix.ywrapstep = 1;
info->fix.xpanstep = 0;
info->fix.ypanstep = 0;
-   info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YWRAP |
+   info->flags = FBINFO_HWACCEL_YWRAP |
FBINFO_READS_FAST; /* override SCROLL_REDRAW */
} else {
info->fix.ywrapstep = 0;
@@ -2436,7 +2436,7 @@ static int amifb_set_par(struct fb_info *info)
else
info->fix.xpanstep = 16 << maxfmode;

[PATCH v2 06/18] fbdev/fsl-diu-fb: Remove flag FBINFO_DEFAULT

2023-07-13 Thread Thomas Zimmermann
The flag FBINFO_DEFAULT is 0 and has no effect, as struct fbinfo.flags
has been allocated to zero by dmam_alloc_coherent(__GFP_ZERO). So do not
set it.

Flags should signal differences from the default values. After cleaning
up all occurrences of FBINFO_DEFAULT, the token will be removed.

v2:
* fix commit message (Miguel)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Cc: Timur Tabi 
Cc: Helge Deller 
---
 drivers/video/fbdev/fsl-diu-fb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/fsl-diu-fb.c b/drivers/video/fbdev/fsl-diu-fb.c
index 785eb8a06943..c62b48f27ba9 100644
--- a/drivers/video/fbdev/fsl-diu-fb.c
+++ b/drivers/video/fbdev/fsl-diu-fb.c
@@ -1476,7 +1476,7 @@ static int install_fb(struct fb_info *info)
 
info->var.activate = FB_ACTIVATE_NOW;
info->fbops = _diu_ops;
-   info->flags = FBINFO_DEFAULT | FBINFO_VIRTFB | FBINFO_PARTIAL_PAN_OK |
+   info->flags = FBINFO_VIRTFB | FBINFO_PARTIAL_PAN_OK |
FBINFO_READS_FAST;
info->pseudo_palette = mfbi->pseudo_palette;
 
-- 
2.41.0



[PATCH v2 04/18] fbdev: Remove flag FBINFO_DEFAULT from fbdev drivers

2023-07-13 Thread Thomas Zimmermann
The flag FBINFO_DEFAULT is 0 and has no effect, as struct fbinfo.flags
has been allocated to zero by devm_kzalloc(). So do not set it.

Flags should signal differences from the default values. After cleaning
up all occurrences of FBINFO_DEFAULT, the token will be removed.

v2:
* fix commit message (Miguel)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Cc: Helge Deller 
---
 drivers/video/fbdev/pxafb.c| 1 -
 drivers/video/fbdev/sa1100fb.c | 1 -
 drivers/video/fbdev/wm8505fb.c | 3 +--
 drivers/video/fbdev/xilinxfb.c | 1 -
 4 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/pxafb.c b/drivers/video/fbdev/pxafb.c
index 2a8b1dea3a67..c8c4677d06b4 100644
--- a/drivers/video/fbdev/pxafb.c
+++ b/drivers/video/fbdev/pxafb.c
@@ -1826,7 +1826,6 @@ static struct pxafb_info *pxafb_init_fbinfo(struct device 
*dev,
fbi->fb.var.vmode   = FB_VMODE_NONINTERLACED;
 
fbi->fb.fbops   = _ops;
-   fbi->fb.flags   = FBINFO_DEFAULT;
fbi->fb.node= -1;
 
addr = fbi;
diff --git a/drivers/video/fbdev/sa1100fb.c b/drivers/video/fbdev/sa1100fb.c
index a2408bf00ca0..3d76ce111488 100644
--- a/drivers/video/fbdev/sa1100fb.c
+++ b/drivers/video/fbdev/sa1100fb.c
@@ -1089,7 +1089,6 @@ static struct sa1100fb_info *sa1100fb_init_fbinfo(struct 
device *dev)
fbi->fb.var.vmode   = FB_VMODE_NONINTERLACED;
 
fbi->fb.fbops   = _ops;
-   fbi->fb.flags   = FBINFO_DEFAULT;
fbi->fb.monspecs= monspecs;
fbi->fb.pseudo_palette  = fbi->pseudo_palette;
 
diff --git a/drivers/video/fbdev/wm8505fb.c b/drivers/video/fbdev/wm8505fb.c
index 10a8b1250103..5833147aa43d 100644
--- a/drivers/video/fbdev/wm8505fb.c
+++ b/drivers/video/fbdev/wm8505fb.c
@@ -285,8 +285,7 @@ static int wm8505fb_probe(struct platform_device *pdev)
fbi->fb.fix.accel   = FB_ACCEL_NONE;
 
fbi->fb.fbops   = _ops;
-   fbi->fb.flags   = FBINFO_DEFAULT
-   | FBINFO_HWACCEL_COPYAREA
+   fbi->fb.flags   = FBINFO_HWACCEL_COPYAREA
| FBINFO_HWACCEL_FILLRECT
| FBINFO_HWACCEL_XPAN
| FBINFO_HWACCEL_YPAN
diff --git a/drivers/video/fbdev/xilinxfb.c b/drivers/video/fbdev/xilinxfb.c
index 2aa3a528277f..768a281a8d2c 100644
--- a/drivers/video/fbdev/xilinxfb.c
+++ b/drivers/video/fbdev/xilinxfb.c
@@ -324,7 +324,6 @@ static int xilinxfb_assign(struct platform_device *pdev,
drvdata->info.fix.line_length = pdata->xvirt * BYTES_PER_PIXEL;
 
drvdata->info.pseudo_palette = drvdata->pseudo_palette;
-   drvdata->info.flags = FBINFO_DEFAULT;
drvdata->info.var = xilinx_fb_var;
drvdata->info.var.height = pdata->screen_height_mm;
drvdata->info.var.width = pdata->screen_width_mm;
-- 
2.41.0



[PATCH v2 03/18] fbdev: Remove flag FBINFO_DEFAULT from fbdev drivers

2023-07-13 Thread Thomas Zimmermann
The flag FBINFO_DEFAULT is 0 and has no effect, as struct fbinfo.flags
has been allocated to zero by kzalloc(). So do not set it.

Flags should signal differences from the default values. After cleaning
up all occurrences of FBINFO_DEFAULT, the token will be removed.

v2:
* fix commit message (Miguel)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Cc: Helge Deller 
Cc: Russell King 
---
 drivers/video/fbdev/controlfb.c   | 2 +-
 drivers/video/fbdev/cyber2000fb.c | 2 +-
 drivers/video/fbdev/valkyriefb.c  | 1 -
 drivers/video/fbdev/vermilion/vermilion.c | 2 +-
 drivers/video/fbdev/vt8500lcdfb.c | 3 +--
 5 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/controlfb.c b/drivers/video/fbdev/controlfb.c
index 82eeb139c4eb..717134c141ff 100644
--- a/drivers/video/fbdev/controlfb.c
+++ b/drivers/video/fbdev/controlfb.c
@@ -775,7 +775,7 @@ static void __init control_init_info(struct fb_info *info, 
struct fb_info_contro
info->par = >par;
info->fbops = _ops;
info->pseudo_palette = p->pseudo_palette;
-info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
+   info->flags = FBINFO_HWACCEL_YPAN;
info->screen_base = p->frame_buffer + CTRLFB_OFF;
 
fb_alloc_cmap(>cmap, 256, 0);
diff --git a/drivers/video/fbdev/cyber2000fb.c 
b/drivers/video/fbdev/cyber2000fb.c
index 38c0a6866d76..98ea56a9abf1 100644
--- a/drivers/video/fbdev/cyber2000fb.c
+++ b/drivers/video/fbdev/cyber2000fb.c
@@ -1459,7 +1459,7 @@ static struct cfb_info *cyberpro_alloc_fb_info(unsigned 
int id, char *name)
cfb->fb.var.accel_flags = FB_ACCELF_TEXT;
 
cfb->fb.fbops   = _ops;
-   cfb->fb.flags   = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
+   cfb->fb.flags   = FBINFO_HWACCEL_YPAN;
cfb->fb.pseudo_palette  = cfb->pseudo_palette;
 
spin_lock_init(>reg_b0_lock);
diff --git a/drivers/video/fbdev/valkyriefb.c b/drivers/video/fbdev/valkyriefb.c
index b166b7cfe0e5..fd4488777032 100644
--- a/drivers/video/fbdev/valkyriefb.c
+++ b/drivers/video/fbdev/valkyriefb.c
@@ -535,7 +535,6 @@ static int __init valkyrie_init_info(struct fb_info *info,
 {
info->fbops = _ops;
info->screen_base = p->frame_buffer + 0x1000;
-   info->flags = FBINFO_DEFAULT;
info->pseudo_palette = p->pseudo_palette;
info->par = >par;
return fb_alloc_cmap(>cmap, 256, 0);
diff --git a/drivers/video/fbdev/vermilion/vermilion.c 
b/drivers/video/fbdev/vermilion/vermilion.c
index 32e74e02a02f..71584c775efd 100644
--- a/drivers/video/fbdev/vermilion/vermilion.c
+++ b/drivers/video/fbdev/vermilion/vermilion.c
@@ -477,7 +477,7 @@ static int vml_pci_probe(struct pci_dev *dev, const struct 
pci_device_id *id)
}
 
info = >info;
-   info->flags = FBINFO_DEFAULT | FBINFO_PARTIAL_PAN_OK;
+   info->flags = FBINFO_PARTIAL_PAN_OK;
 
err = vmlfb_enable_mmio(par);
if (err)
diff --git a/drivers/video/fbdev/vt8500lcdfb.c 
b/drivers/video/fbdev/vt8500lcdfb.c
index 31d4e85b220c..42d39a9d5130 100644
--- a/drivers/video/fbdev/vt8500lcdfb.c
+++ b/drivers/video/fbdev/vt8500lcdfb.c
@@ -300,8 +300,7 @@ static int vt8500lcd_probe(struct platform_device *pdev)
fbi->fb.var.vmode   = FB_VMODE_NONINTERLACED;
 
fbi->fb.fbops   = _ops;
-   fbi->fb.flags   = FBINFO_DEFAULT
-   | FBINFO_HWACCEL_COPYAREA
+   fbi->fb.flags   = FBINFO_HWACCEL_COPYAREA
| FBINFO_HWACCEL_FILLRECT
| FBINFO_HWACCEL_YPAN
| FBINFO_VIRTFB
-- 
2.41.0



[PATCH v2 01/18] drm: Remove flag FBINFO_DEFAULT from fbdev emulation

2023-07-13 Thread Thomas Zimmermann
The flag FBINFO_DEFAULT is 0 and has no effect, as struct fbinfo.flags
has been allocated to zero by framebuffer_alloc(). So do not set it.

Flags should signal differences from the default values. After cleaning
up all occurrences of FBINFO_DEFAULT, the token will be removed.

v2:
* fix commit message (Miguel)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Cc: Patrik Jakobsson 
Cc: Alex Deucher 
Cc: "Christian König" 
Cc: "Pan, Xinhui" 
---
 drivers/gpu/drm/drm_fbdev_dma.c   | 1 -
 drivers/gpu/drm/drm_fbdev_generic.c   | 1 -
 drivers/gpu/drm/gma500/fbdev.c| 2 +-
 drivers/gpu/drm/radeon/radeon_fbdev.c | 2 +-
 4 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_fbdev_dma.c b/drivers/gpu/drm/drm_fbdev_dma.c
index f9b1f7cd31b7..ee7c265b0585 100644
--- a/drivers/gpu/drm/drm_fbdev_dma.c
+++ b/drivers/gpu/drm/drm_fbdev_dma.c
@@ -123,7 +123,6 @@ static int drm_fbdev_dma_helper_fb_probe(struct 
drm_fb_helper *fb_helper,
drm_fb_helper_fill_info(info, fb_helper, sizes);
 
info->fbops = _fbdev_dma_fb_ops;
-   info->flags = FBINFO_DEFAULT;
 
/* screen */
info->flags |= FBINFO_VIRTFB; /* system memory */
diff --git a/drivers/gpu/drm/drm_fbdev_generic.c 
b/drivers/gpu/drm/drm_fbdev_generic.c
index b9343fb6cf13..a0ea042b1526 100644
--- a/drivers/gpu/drm/drm_fbdev_generic.c
+++ b/drivers/gpu/drm/drm_fbdev_generic.c
@@ -109,7 +109,6 @@ static int drm_fbdev_generic_helper_fb_probe(struct 
drm_fb_helper *fb_helper,
drm_fb_helper_fill_info(info, fb_helper, sizes);
 
info->fbops = _fbdev_generic_fb_ops;
-   info->flags = FBINFO_DEFAULT;
 
/* screen */
info->flags |= FBINFO_VIRTFB | FBINFO_READS_FAST;
diff --git a/drivers/gpu/drm/gma500/fbdev.c b/drivers/gpu/drm/gma500/fbdev.c
index 054426549fc6..be8f5fbd5260 100644
--- a/drivers/gpu/drm/gma500/fbdev.c
+++ b/drivers/gpu/drm/gma500/fbdev.c
@@ -215,7 +215,7 @@ static int psb_fbdev_fb_probe(struct drm_fb_helper 
*fb_helper,
}
 
info->fbops = _fbdev_fb_ops;
-   info->flags = FBINFO_DEFAULT;
+
/* Accessed stolen memory directly */
info->screen_base = dev_priv->vram_addr + backing->offset;
info->screen_size = size;
diff --git a/drivers/gpu/drm/radeon/radeon_fbdev.c 
b/drivers/gpu/drm/radeon/radeon_fbdev.c
index f941e2e7cae6..68c06ac9acce 100644
--- a/drivers/gpu/drm/radeon/radeon_fbdev.c
+++ b/drivers/gpu/drm/radeon/radeon_fbdev.c
@@ -253,7 +253,7 @@ static int radeon_fbdev_fb_helper_fb_probe(struct 
drm_fb_helper *fb_helper,
}
 
info->fbops = _fbdev_fb_ops;
-   info->flags = FBINFO_DEFAULT;
+
/* radeon resume is fragile and needs a vt switch to help it along */
info->skip_vt_switch = false;
 
-- 
2.41.0



[PATCH v2 00/18] fbdev: Remove FBINFO_DEFAULT and FBINFO_FLAG_DEFAULT flags

2023-07-13 Thread Thomas Zimmermann
Remove the unused flags FBINFO_DEFAULT and FBINFO_FLAG_DEFAULT from
fbdev and drivers, as briefly discussed at [1]. Both flags were maybe
useful when fbdev had special handling for driver modules. With
commit 376b3ff54c9a ("fbdev: Nuke FBINFO_MODULE"), they are both 0
and have no further effect.

Patches 1 to 7 remove FBINFO_DEFAULT from drivers. Patches 2 to 5
split this by the way the fb_info struct is being allocated. All flags
are cleared to zero during the allocation.

Patches 8 to 16 do the same for FBINFO_FLAG_DEFAULT. Patch 8 fixes
an actual bug in how arch/sh uses the tokne for struct fb_videomode,
which is unrelated.

Patch 17 removes both flag constants from  and patch 18
documents the zero'ed memory returned by framebuffer_alloc().

v2:
* sh: use FB_MODE_IS_UNKNOWN (Adrian)
* fix commit messages (Miguel)
* document framebuffer_alloc()'s zero'ed memory (Miguel)

[1] 
https://lore.kernel.org/dri-devel/877crer8fm@minerva.mail-host-address-is-not-set/

Thomas Zimmermann (18):
  drm: Remove flag FBINFO_DEFAULT from fbdev emulation
  fbdev: Remove flag FBINFO_DEFAULT from fbdev drivers
  fbdev: Remove flag FBINFO_DEFAULT from fbdev drivers
  fbdev: Remove flag FBINFO_DEFAULT from fbdev drivers
  fbdev: Remove flag FBINFO_DEFAULT from fbdev drivers
  fbdev/fsl-diu-fb: Remove flag FBINFO_DEFAULT
  vfio-mdev: Remove flag FBINFO_DEFAULT from fbdev sample driver
  sh: Assign FB_MODE_IS_UNKNOWN to struct fb_videomode.flag
  auxdisplay: Remove flag FBINFO_FLAG_DEFAULT from fbdev drivers
  hid/picolcd: Remove flag FBINFO_FLAG_DEFAULT from fbdev driver
  media: Remove flag FBINFO_FLAG_DEFAULT from fbdev drivers
  staging: Remove flag FBINFO_FLAG_DEFAULT from fbdev drivers
  fbdev: Remove flag FBINFO_FLAG_DEFAULT from fbdev drivers
  fbdev: Remove flag FBINFO_FLAG_DEFAULT from fbdev drivers
  fbdev/atafb: Remove flag FBINFO_FLAG_DEFAULT
  fbdev/pxafb: Remove flag FBINFO_FLAG_DEFAULT
  fbdev: Remove FBINFO_DEFAULT and FBINFO_FLAG_DEFAULT
  fbdev: Document that framebuffer_alloc() returns zero'ed data

 arch/sh/boards/mach-sh7763rdp/setup.c  | 2 +-
 drivers/auxdisplay/cfag12864bfb.c  | 1 -
 drivers/auxdisplay/ht16k33.c   | 1 -
 drivers/gpu/drm/drm_fbdev_dma.c| 1 -
 drivers/gpu/drm/drm_fbdev_generic.c| 1 -
 drivers/gpu/drm/gma500/fbdev.c | 2 +-
 drivers/gpu/drm/radeon/radeon_fbdev.c  | 2 +-
 drivers/hid/hid-picolcd_fb.c   | 1 -
 drivers/media/pci/ivtv/ivtvfb.c| 1 -
 drivers/media/test-drivers/vivid/vivid-osd.c   | 1 -
 drivers/staging/fbtft/fbtft-core.c | 2 +-
 drivers/staging/sm750fb/sm750.c| 1 -
 drivers/video/fbdev/68328fb.c  | 2 +-
 drivers/video/fbdev/acornfb.c  | 2 +-
 drivers/video/fbdev/amba-clcd.c| 1 -
 drivers/video/fbdev/amifb.c| 5 ++---
 drivers/video/fbdev/arcfb.c| 1 -
 drivers/video/fbdev/asiliantfb.c   | 1 -
 drivers/video/fbdev/atafb.c| 1 -
 drivers/video/fbdev/atmel_lcdfb.c  | 2 +-
 drivers/video/fbdev/aty/aty128fb.c | 1 -
 drivers/video/fbdev/aty/atyfb_base.c   | 3 +--
 drivers/video/fbdev/aty/radeon_base.c  | 3 +--
 drivers/video/fbdev/broadsheetfb.c | 2 +-
 drivers/video/fbdev/bw2.c  | 1 -
 drivers/video/fbdev/carminefb.c| 1 -
 drivers/video/fbdev/cg14.c | 2 +-
 drivers/video/fbdev/cg3.c  | 1 -
 drivers/video/fbdev/cg6.c  | 2 +-
 drivers/video/fbdev/chipsfb.c  | 1 -
 drivers/video/fbdev/cirrusfb.c | 3 +--
 drivers/video/fbdev/clps711x-fb.c  | 1 -
 drivers/video/fbdev/cobalt_lcdfb.c | 1 -
 drivers/video/fbdev/controlfb.c| 2 +-
 drivers/video/fbdev/core/fb_info.c | 3 ++-
 drivers/video/fbdev/cyber2000fb.c  | 2 +-
 drivers/video/fbdev/da8xx-fb.c | 1 -
 drivers/video/fbdev/efifb.c| 1 -
 drivers/video/fbdev/ep93xx-fb.c| 1 -
 drivers/video/fbdev/ffb.c  | 3 +--
 drivers/video/fbdev/fm2fb.c| 1 -
 drivers/video/fbdev/fsl-diu-fb.c   | 2 +-
 drivers/video/fbdev/g364fb.c   | 2 +-
 drivers/video/fbdev/gbefb.c| 1 -
 drivers/video/fbdev/geode/gx1fb_core.c | 1 -
 drivers/video/fbdev/geode/gxfb_core.c  | 1 -
 drivers/video/fbdev/geode/lxfb_core.c  | 1 -
 drivers/video/fbdev/goldfishfb.c   | 1 -
 drivers/video/fbdev/grvga.c| 2 +-
 drivers/video/fbdev/gxt4500.c  | 3 +--
 drivers/video/fbdev/hecubafb.c | 2 +-
 drivers/video/fbdev/hgafb.c| 2 +-
 drivers/video/fbdev/hitfb.c| 2 +-
 drivers/video/fbdev/hpfb.c

[PATCH v2 02/18] fbdev: Remove flag FBINFO_DEFAULT from fbdev drivers

2023-07-13 Thread Thomas Zimmermann
The flag FBINFO_DEFAULT is 0 and has no effect, as struct fbinfo.flags
has been allocated to zero by a static declaration. So do not set it.

Flags should signal differences from the default values. After cleaning
up all occurrences of FBINFO_DEFAULT, the token will be removed.

v2:
* fix commit message (Miguel)

Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 
Cc: Helge Deller 
---
 drivers/video/fbdev/68328fb.c  | 2 +-
 drivers/video/fbdev/acornfb.c  | 2 +-
 drivers/video/fbdev/g364fb.c   | 2 +-
 drivers/video/fbdev/hpfb.c | 1 -
 drivers/video/fbdev/macfb.c| 1 -
 drivers/video/fbdev/maxinefb.c | 1 -
 6 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/video/fbdev/68328fb.c b/drivers/video/fbdev/68328fb.c
index 07d6e8dc686b..956dd2399cc0 100644
--- a/drivers/video/fbdev/68328fb.c
+++ b/drivers/video/fbdev/68328fb.c
@@ -448,7 +448,7 @@ static int __init mc68x328fb_init(void)
fb_info.var.red.offset = fb_info.var.green.offset = 
fb_info.var.blue.offset = 0;
}
fb_info.pseudo_palette = _pseudo_palette;
-   fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
+   fb_info.flags = FBINFO_HWACCEL_YPAN;
 
if (fb_alloc_cmap(_info.cmap, 256, 0))
return -ENOMEM;
diff --git a/drivers/video/fbdev/acornfb.c b/drivers/video/fbdev/acornfb.c
index 1b72edc01cfb..8fec21dfca09 100644
--- a/drivers/video/fbdev/acornfb.c
+++ b/drivers/video/fbdev/acornfb.c
@@ -694,7 +694,7 @@ static void acornfb_init_fbinfo(void)
first = 0;
 
fb_info.fbops   = _ops;
-   fb_info.flags   = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
+   fb_info.flags   = FBINFO_HWACCEL_YPAN;
fb_info.pseudo_palette  = current_par.pseudo_palette;
 
strcpy(fb_info.fix.id, "Acorn");
diff --git a/drivers/video/fbdev/g364fb.c b/drivers/video/fbdev/g364fb.c
index c5b7673ddc6c..0825cbde116e 100644
--- a/drivers/video/fbdev/g364fb.c
+++ b/drivers/video/fbdev/g364fb.c
@@ -219,7 +219,7 @@ int __init g364fb_init(void)
fb_info.screen_base = (char *) G364_MEM_BASE;   /* virtual kernel 
address */
fb_info.var = fb_var;
fb_info.fix = fb_fix;
-   fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
+   fb_info.flags = FBINFO_HWACCEL_YPAN;
 
fb_alloc_cmap(_info.cmap, 255, 0);
 
diff --git a/drivers/video/fbdev/hpfb.c b/drivers/video/fbdev/hpfb.c
index 77fbff47b1a8..406c1383cbda 100644
--- a/drivers/video/fbdev/hpfb.c
+++ b/drivers/video/fbdev/hpfb.c
@@ -287,7 +287,6 @@ static int hpfb_init_one(unsigned long phys_base, unsigned 
long virt_base)
else
strcat(fb_info.fix.id, "Catseye");
fb_info.fbops = _ops;
-   fb_info.flags = FBINFO_DEFAULT;
fb_info.var   = hpfb_defined;
fb_info.screen_base = (char *)fb_start;
 
diff --git a/drivers/video/fbdev/macfb.c b/drivers/video/fbdev/macfb.c
index 44ff860a3f37..5ca208d992cc 100644
--- a/drivers/video/fbdev/macfb.c
+++ b/drivers/video/fbdev/macfb.c
@@ -876,7 +876,6 @@ static int __init macfb_init(void)
fb_info.var = macfb_defined;
fb_info.fix = macfb_fix;
fb_info.pseudo_palette  = pseudo_palette;
-   fb_info.flags   = FBINFO_DEFAULT;
 
err = fb_alloc_cmap(_info.cmap, video_cmap_len, 0);
if (err)
diff --git a/drivers/video/fbdev/maxinefb.c b/drivers/video/fbdev/maxinefb.c
index 4e6b05232ae2..0ac1873b2acb 100644
--- a/drivers/video/fbdev/maxinefb.c
+++ b/drivers/video/fbdev/maxinefb.c
@@ -155,7 +155,6 @@ int __init maxinefb_init(void)
fb_info.screen_base = (char *)maxinefb_fix.smem_start;
fb_info.var = maxinefb_defined;
fb_info.fix = maxinefb_fix;
-   fb_info.flags = FBINFO_DEFAULT;
 
fb_alloc_cmap(_info.cmap, 256, 0);
 
-- 
2.41.0



Re: [PATCH rfc -next 00/10] mm: convert to generic VMA lock-based page fault

2023-07-13 Thread Kefeng Wang

Please ignore this one...

On 2023/7/13 17:51, Kefeng Wang wrote:

Add a generic VMA lock-based page fault handler in mm core, and convert
architectures to use it, which eliminate architectures's duplicated codes.

With it, we can avoid multiple changes in architectures's code if we
add new feature or bugfix.

This fixes riscv missing change about commit 38b3aec8e8d2 "mm: drop per-VMA
lock when returning VM_FAULT_RETRY or VM_FAULT_COMPLETED", and in the end,
we enable this feature on ARM32/Loongarch too.

This is based on next-20230713, only built test(no loongarch compiler,
so except loongarch).

Kefeng Wang (10):
   mm: add a generic VMA lock-based page fault handler
   x86: mm: use try_vma_locked_page_fault()
   arm64: mm: use try_vma_locked_page_fault()
   s390: mm: use try_vma_locked_page_fault()
   powerpc: mm: use try_vma_locked_page_fault()
   riscv: mm: use try_vma_locked_page_fault()
   ARM: mm: try VMA lock-based page fault handling first
   loongarch: mm: cleanup __do_page_fault()
   loongarch: mm: add access_error() helper
   loongarch: mm: try VMA lock-based page fault handling first

  arch/arm/Kconfig  |  1 +
  arch/arm/mm/fault.c   | 15 ++-
  arch/arm64/mm/fault.c | 28 +++-
  arch/loongarch/Kconfig|  1 +
  arch/loongarch/mm/fault.c | 92 ---
  arch/powerpc/mm/fault.c   | 54 ++-
  arch/riscv/mm/fault.c | 38 +++-
  arch/s390/mm/fault.c  | 23 +++---
  arch/x86/mm/fault.c   | 39 +++--
  include/linux/mm.h| 28 
  mm/memory.c   | 42 ++
  11 files changed, 206 insertions(+), 155 deletions(-)



[PATCH rfc -next 07/10] ARM: mm: try VMA lock-based page fault handling first

2023-07-13 Thread Kefeng Wang
Attempt VMA lock-based page fault handling first, and fall back
to the existing mmap_lock-based handling if that fails.

Signed-off-by: Kefeng Wang 
---
 arch/arm/Kconfig|  1 +
 arch/arm/mm/fault.c | 15 ++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 1a6a6eb48a15..8b6d4507ccee 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -34,6 +34,7 @@ config ARM
select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT if CPU_V7
select ARCH_SUPPORTS_ATOMIC_RMW
select ARCH_SUPPORTS_HUGETLBFS if ARM_LPAE
+   select ARCH_SUPPORTS_PER_VMA_LOCK
select ARCH_USE_BUILTIN_BSWAP
select ARCH_USE_CMPXCHG_LOCKREF
select ARCH_USE_MEMTEST
diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
index fef62e4a9edd..c44b83841e36 100644
--- a/arch/arm/mm/fault.c
+++ b/arch/arm/mm/fault.c
@@ -244,6 +244,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct 
pt_regs *regs)
vm_fault_t fault;
unsigned int flags = FAULT_FLAG_DEFAULT;
unsigned long vm_flags = VM_ACCESS_FLAGS;
+   struct vm_locked_fault vmlf;
 
if (kprobe_page_fault(regs, fsr))
return 0;
@@ -278,6 +279,18 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct 
pt_regs *regs)
 
perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr);
 
+   VM_LOCKED_FAULT_INIT(vmlf, mm, addr, flags, vm_flags, regs, fsr);
+   if (try_vma_locked_page_fault(, ))
+   goto retry;
+   else if (!(fault | VM_FAULT_RETRY))
+   goto done;
+
+   if (fault_signal_pending(fault, regs)) {
+   if (!user_mode(regs))
+   goto no_context;
+   return 0;
+   }
+
 retry:
vma = lock_mm_and_find_vma(mm, addr, regs);
if (unlikely(!vma)) {
@@ -316,7 +329,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct 
pt_regs *regs)
}
 
mmap_read_unlock(mm);
-
+done:
/*
 * Handle the "normal" case first - VM_FAULT_MAJOR
 */
-- 
2.27.0



[PATCH rfc -next 04/10] s390: mm: use try_vma_locked_page_fault()

2023-07-13 Thread Kefeng Wang
Use new try_vma_locked_page_fault() helper to simplify code.
No functional change intended.

Signed-off-by: Kefeng Wang 
---
 arch/s390/mm/fault.c | 23 ++-
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c
index 40a71063949b..97e511690352 100644
--- a/arch/s390/mm/fault.c
+++ b/arch/s390/mm/fault.c
@@ -362,6 +362,7 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, 
int access)
struct task_struct *tsk;
struct mm_struct *mm;
struct vm_area_struct *vma;
+   struct vm_locked_fault vmlf;
enum fault_type type;
unsigned long address;
unsigned int flags;
@@ -407,31 +408,19 @@ static inline vm_fault_t do_exception(struct pt_regs 
*regs, int access)
access = VM_WRITE;
if (access == VM_WRITE)
flags |= FAULT_FLAG_WRITE;
-#ifdef CONFIG_PER_VMA_LOCK
-   if (!(flags & FAULT_FLAG_USER))
-   goto lock_mmap;
-   vma = lock_vma_under_rcu(mm, address);
-   if (!vma)
-   goto lock_mmap;
-   if (!(vma->vm_flags & access)) {
-   vma_end_read(vma);
+
+   VM_LOCKED_FAULT_INIT(vmlf, mm, address, flags, access, regs, 0);
+   if (try_vma_locked_page_fault(, ))
goto lock_mmap;
-   }
-   fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, 
regs);
-   if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
-   vma_end_read(vma);
-   if (!(fault & VM_FAULT_RETRY)) {
-   count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
+   else if (!(fault | VM_FAULT_RETRY))
goto out;
-   }
-   count_vm_vma_lock_event(VMA_LOCK_RETRY);
+
/* Quick path to respond to signals */
if (fault_signal_pending(fault, regs)) {
fault = VM_FAULT_SIGNAL;
goto out;
}
 lock_mmap:
-#endif /* CONFIG_PER_VMA_LOCK */
mmap_read_lock(mm);
 
gmap = NULL;
-- 
2.27.0



[PATCH rfc -next 03/10] arm64: mm: use try_vma_locked_page_fault()

2023-07-13 Thread Kefeng Wang
Use new try_vma_locked_page_fault() helper to simplify code.
No functional change intended.

Signed-off-by: Kefeng Wang 
---
 arch/arm64/mm/fault.c | 28 +---
 1 file changed, 5 insertions(+), 23 deletions(-)

diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index b8c80f7b8a5f..614bb53fc1bc 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -537,6 +537,7 @@ static int __kprobes do_page_fault(unsigned long far, 
unsigned long esr,
unsigned int mm_flags = FAULT_FLAG_DEFAULT;
unsigned long addr = untagged_addr(far);
struct vm_area_struct *vma;
+   struct vm_locked_fault vmlf;
 
if (kprobe_page_fault(regs, esr))
return 0;
@@ -587,27 +588,11 @@ static int __kprobes do_page_fault(unsigned long far, 
unsigned long esr,
 
perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr);
 
-#ifdef CONFIG_PER_VMA_LOCK
-   if (!(mm_flags & FAULT_FLAG_USER))
-   goto lock_mmap;
-
-   vma = lock_vma_under_rcu(mm, addr);
-   if (!vma)
-   goto lock_mmap;
-
-   if (!(vma->vm_flags & vm_flags)) {
-   vma_end_read(vma);
-   goto lock_mmap;
-   }
-   fault = handle_mm_fault(vma, addr, mm_flags | FAULT_FLAG_VMA_LOCK, 
regs);
-   if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
-   vma_end_read(vma);
-
-   if (!(fault & VM_FAULT_RETRY)) {
-   count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
+   VM_LOCKED_FAULT_INIT(vmlf, mm, addr, mm_flags, vm_flags, regs, esr);
+   if (try_vma_locked_page_fault(, ))
+   goto retry;
+   else if (!(fault | VM_FAULT_RETRY))
goto done;
-   }
-   count_vm_vma_lock_event(VMA_LOCK_RETRY);
 
/* Quick path to respond to signals */
if (fault_signal_pending(fault, regs)) {
@@ -615,9 +600,6 @@ static int __kprobes do_page_fault(unsigned long far, 
unsigned long esr,
goto no_context;
return 0;
}
-lock_mmap:
-#endif /* CONFIG_PER_VMA_LOCK */
-
 retry:
vma = lock_mm_and_find_vma(mm, addr, regs);
if (unlikely(!vma)) {
-- 
2.27.0



[PATCH rfc -next 01/10] mm: add a generic VMA lock-based page fault handler

2023-07-13 Thread Kefeng Wang
There are more and more architectures enabled ARCH_SUPPORTS_PER_VMA_LOCK,
eg, x86, arm64, powerpc and s390, and riscv, those implementation are very
similar which results in some duplicated codes, let's add a generic VMA
lock-based page fault handler to eliminate them, and which also make it
easy to support this feature on new architectures.

Signed-off-by: Kefeng Wang 
---
 include/linux/mm.h | 28 
 mm/memory.c| 42 ++
 2 files changed, 70 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index c7886784832b..cba1b7b19c9d 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -633,6 +633,15 @@ static inline void vma_numab_state_init(struct 
vm_area_struct *vma) {}
 static inline void vma_numab_state_free(struct vm_area_struct *vma) {}
 #endif /* CONFIG_NUMA_BALANCING */
 
+struct vm_locked_fault {
+   struct mm_struct *mm;
+   unsigned long address;
+   unsigned int fault_flags;
+   unsigned long vm_flags;
+   struct pt_regs *regs;
+   unsigned long fault_code;
+};
+
 #ifdef CONFIG_PER_VMA_LOCK
 /*
  * Try to read-lock a vma. The function is allowed to occasionally yield false
@@ -733,6 +742,19 @@ static inline void assert_fault_locked(struct vm_fault 
*vmf)
 struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm,
  unsigned long address);
 
+#define VM_LOCKED_FAULT_INIT(_name, _mm, _address, _fault_flags, _vm_flags, 
_regs, _fault_code) \
+   _name.mm= _mm;  \
+   _name.address   = _address; \
+   _name.fault_flags   = _fault_flags; \
+   _name.vm_flags  = _vm_flags;\
+   _name.regs  = _regs;\
+   _name.fault_code= _fault_code
+
+int __weak arch_vma_check_access(struct vm_area_struct *vma,
+struct vm_locked_fault *vmlf);
+
+int try_vma_locked_page_fault(struct vm_locked_fault *vmlf, vm_fault_t *ret);
+
 #else /* CONFIG_PER_VMA_LOCK */
 
 static inline bool vma_start_read(struct vm_area_struct *vma)
@@ -742,6 +764,12 @@ static inline void vma_start_write(struct vm_area_struct 
*vma) {}
 static inline void vma_assert_write_locked(struct vm_area_struct *vma) {}
 static inline void vma_mark_detached(struct vm_area_struct *vma,
 bool detached) {}
+#define VM_LOCKED_FAULT_INIT(_name, _mm, _address, _fault_flags, _vm_flags, 
_regs, _fault_code)
+static inline int try_vma_locked_page_fault(struct vm_locked_fault *vmlf,
+   vm_fault_t *ret)
+{
+   return -EINVAL;
+}
 
 static inline void release_fault_lock(struct vm_fault *vmf)
 {
diff --git a/mm/memory.c b/mm/memory.c
index ad790394963a..d3f5d1270e7a 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5449,6 +5449,48 @@ struct vm_area_struct *lock_vma_under_rcu(struct 
mm_struct *mm,
count_vm_vma_lock_event(VMA_LOCK_ABORT);
return NULL;
 }
+
+int __weak arch_vma_check_access(struct vm_area_struct *vma,
+struct vm_locked_fault *vmlf)
+{
+   if (!(vma->vm_flags & vmlf->vm_flags))
+   return -EINVAL;
+   return 0;
+}
+
+int try_vma_locked_page_fault(struct vm_locked_fault *vmlf, vm_fault_t *ret)
+{
+   struct vm_area_struct *vma;
+   vm_fault_t fault;
+
+   if (!(vmlf->fault_flags & FAULT_FLAG_USER))
+   return -EINVAL;
+
+   vma = lock_vma_under_rcu(vmlf->mm, vmlf->address);
+   if (!vma)
+   return -EINVAL;
+
+   if (arch_vma_check_access(vma, vmlf)) {
+   vma_end_read(vma);
+   return -EINVAL;
+   }
+
+   fault = handle_mm_fault(vma, vmlf->address,
+   vmlf->fault_flags | FAULT_FLAG_VMA_LOCK,
+   vmlf->regs);
+   *ret = fault;
+
+   if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
+   vma_end_read(vma);
+
+   if ((fault & VM_FAULT_RETRY))
+   count_vm_vma_lock_event(VMA_LOCK_RETRY);
+   else
+   count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
+
+   return 0;
+}
+
 #endif /* CONFIG_PER_VMA_LOCK */
 
 #ifndef __PAGETABLE_P4D_FOLDED
-- 
2.27.0



[PATCH rfc -next 00/10] mm: convert to generic VMA lock-based page fault

2023-07-13 Thread Kefeng Wang
Add a generic VMA lock-based page fault handler in mm core, and convert
architectures to use it, which eliminate architectures's duplicated codes.

With it, we can avoid multiple changes in architectures's code if we 
add new feature or bugfix.

This fixes riscv missing change about commit 38b3aec8e8d2 "mm: drop per-VMA
lock when returning VM_FAULT_RETRY or VM_FAULT_COMPLETED", and in the end,
we enable this feature on ARM32/Loongarch too.

This is based on next-20230713, only built test(no loongarch compiler,
so except loongarch).

Kefeng Wang (10):
  mm: add a generic VMA lock-based page fault handler
  x86: mm: use try_vma_locked_page_fault()
  arm64: mm: use try_vma_locked_page_fault()
  s390: mm: use try_vma_locked_page_fault()
  powerpc: mm: use try_vma_locked_page_fault()
  riscv: mm: use try_vma_locked_page_fault()
  ARM: mm: try VMA lock-based page fault handling first
  loongarch: mm: cleanup __do_page_fault()
  loongarch: mm: add access_error() helper
  loongarch: mm: try VMA lock-based page fault handling first

 arch/arm/Kconfig  |  1 +
 arch/arm/mm/fault.c   | 15 ++-
 arch/arm64/mm/fault.c | 28 +++-
 arch/loongarch/Kconfig|  1 +
 arch/loongarch/mm/fault.c | 92 ---
 arch/powerpc/mm/fault.c   | 54 ++-
 arch/riscv/mm/fault.c | 38 +++-
 arch/s390/mm/fault.c  | 23 +++---
 arch/x86/mm/fault.c   | 39 +++--
 include/linux/mm.h| 28 
 mm/memory.c   | 42 ++
 11 files changed, 206 insertions(+), 155 deletions(-)

-- 
2.27.0



[PATCH rfc -next 10/10] loongarch: mm: try VMA lock-based page fault handling first

2023-07-13 Thread Kefeng Wang
Attempt VMA lock-based page fault handling first, and fall back
to the existing mmap_lock-based handling if that fails.

Signed-off-by: Kefeng Wang 
---
 arch/loongarch/Kconfig|  1 +
 arch/loongarch/mm/fault.c | 26 ++
 2 files changed, 27 insertions(+)

diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
index 397203e18800..afb0ccabab97 100644
--- a/arch/loongarch/Kconfig
+++ b/arch/loongarch/Kconfig
@@ -53,6 +53,7 @@ config LOONGARCH
select ARCH_SUPPORTS_LTO_CLANG
select ARCH_SUPPORTS_LTO_CLANG_THIN
select ARCH_SUPPORTS_NUMA_BALANCING
+   select ARCH_SUPPORTS_PER_VMA_LOCK
select ARCH_USE_BUILTIN_BSWAP
select ARCH_USE_CMPXCHG_LOCKREF
select ARCH_USE_QUEUED_RWLOCKS
diff --git a/arch/loongarch/mm/fault.c b/arch/loongarch/mm/fault.c
index cde2ea0119fa..7e54bc48813e 100644
--- a/arch/loongarch/mm/fault.c
+++ b/arch/loongarch/mm/fault.c
@@ -136,6 +136,17 @@ static inline bool access_error(unsigned int flags, struct 
pt_regs *regs,
return false;
 }
 
+#ifdef CONFIG_PER_VMA_LOCK
+int arch_vma_check_access(struct vm_area_struct *vma,
+ struct vm_locked_fault *vmlf)
+{
+   if (unlikely(access_error(vmlf->fault_flags, vmlf->regs, vmlf->address,
+vma)))
+   return -EINVAL;
+   return 0;
+}
+#endif
+
 /*
  * This routine handles page faults.  It determines the address,
  * and the problem, and then passes it off to one of the appropriate
@@ -149,6 +160,7 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
struct task_struct *tsk = current;
struct mm_struct *mm = tsk->mm;
struct vm_area_struct *vma = NULL;
+   struct vm_locked_fault vmlf;
vm_fault_t fault;
 
if (kprobe_page_fault(regs, current->thread.trap_nr))
@@ -183,6 +195,19 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
flags |= FAULT_FLAG_WRITE;
 
perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
+
+   VM_LOCKED_FAULT_INIT(vmlf, mm, address, flags, 0, regs, 0);
+   if (try_vma_locked_page_fault(, ))
+   goto retry;
+   else if (!(fault | VM_FAULT_RETRY))
+   goto done;
+
+   if (fault_signal_pending(fault, regs)) {
+   if (!user_mode(regs))
+   no_context(regs, address);
+   return;
+   }
+
 retry:
vma = lock_mm_and_find_vma(mm, address, regs);
if (unlikely(!vma))
@@ -223,6 +248,7 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
 
mmap_read_unlock(mm);
 
+done:
if (unlikely(fault & VM_FAULT_ERROR)) {
if (fault & VM_FAULT_OOM) {
do_out_of_memory(regs, address);
-- 
2.27.0



[PATCH rfc -next 09/10] loongarch: mm: add access_error() helper

2023-07-13 Thread Kefeng Wang
Add access_error() to check whether vma could be accessible or not,
which will be used __do_page_fault() and later vma locked based page
fault.

Signed-off-by: Kefeng Wang 
---
 arch/loongarch/mm/fault.c | 30 --
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/arch/loongarch/mm/fault.c b/arch/loongarch/mm/fault.c
index 03d06ee184da..cde2ea0119fa 100644
--- a/arch/loongarch/mm/fault.c
+++ b/arch/loongarch/mm/fault.c
@@ -120,6 +120,22 @@ static void __kprobes do_sigsegv(struct pt_regs *regs,
force_sig_fault(SIGSEGV, si_code, (void __user *)address);
 }
 
+static inline bool access_error(unsigned int flags, struct pt_regs *regs,
+   unsigned long addr, struct vm_area_struct *vma)
+{
+   if (flags & FAULT_FLAG_WRITE) {
+   if (!(vma->vm_flags & VM_WRITE))
+   return true;
+   } else {
+   if (!(vma->vm_flags & VM_READ) && addr != exception_era(regs))
+   return true;
+   if (!(vma->vm_flags & VM_EXEC) && addr == exception_era(regs))
+   return true;
+   }
+
+   return false;
+}
+
 /*
  * This routine handles page faults.  It determines the address,
  * and the problem, and then passes it off to one of the appropriate
@@ -163,6 +179,8 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
 
if (user_mode(regs))
flags |= FAULT_FLAG_USER;
+   if (write)
+   flags |= FAULT_FLAG_WRITE;
 
perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
 retry:
@@ -172,16 +190,8 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
 
si_code = SEGV_ACCERR;
 
-   if (write) {
-   flags |= FAULT_FLAG_WRITE;
-   if (!(vma->vm_flags & VM_WRITE))
-   goto bad_area;
-   } else {
-   if (!(vma->vm_flags & VM_READ) && address != 
exception_era(regs))
-   goto bad_area;
-   if (!(vma->vm_flags & VM_EXEC) && address == 
exception_era(regs))
-   goto bad_area;
-   }
+   if (access_error(flags, regs, vma))
+   goto bad_area;
 
/*
 * If for any reason at all we couldn't handle the fault,
-- 
2.27.0



[PATCH rfc -next 08/10] loongarch: mm: cleanup __do_page_fault()

2023-07-13 Thread Kefeng Wang
Cleanup __do_page_fault() by reuse bad_area_nosemaphore and
bad_area label.

Signed-off-by: Kefeng Wang 
---
 arch/loongarch/mm/fault.c | 36 +++-
 1 file changed, 11 insertions(+), 25 deletions(-)

diff --git a/arch/loongarch/mm/fault.c b/arch/loongarch/mm/fault.c
index da5b6d518cdb..03d06ee184da 100644
--- a/arch/loongarch/mm/fault.c
+++ b/arch/loongarch/mm/fault.c
@@ -151,18 +151,15 @@ static void __kprobes __do_page_fault(struct pt_regs 
*regs,
if (!user_mode(regs))
no_context(regs, address);
else
-   do_sigsegv(regs, write, address, si_code);
-   return;
+   goto bad_area_nosemaphore;
}
 
/*
 * If we're in an interrupt or have no user
 * context, we must not take the fault..
 */
-   if (faulthandler_disabled() || !mm) {
-   do_sigsegv(regs, write, address, si_code);
-   return;
-   }
+   if (faulthandler_disabled() || !mm)
+   goto bad_area_nosemaphore;
 
if (user_mode(regs))
flags |= FAULT_FLAG_USER;
@@ -172,23 +169,7 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
vma = lock_mm_and_find_vma(mm, address, regs);
if (unlikely(!vma))
goto bad_area_nosemaphore;
-   goto good_area;
-
-/*
- * Something tried to access memory that isn't in our memory map..
- * Fix it, but check if it's kernel or user first..
- */
-bad_area:
-   mmap_read_unlock(mm);
-bad_area_nosemaphore:
-   do_sigsegv(regs, write, address, si_code);
-   return;
 
-/*
- * Ok, we have a good vm_area for this memory access, so
- * we can handle it..
- */
-good_area:
si_code = SEGV_ACCERR;
 
if (write) {
@@ -229,14 +210,15 @@ static void __kprobes __do_page_fault(struct pt_regs 
*regs,
 */
goto retry;
}
+
+   mmap_read_unlock(mm);
+
if (unlikely(fault & VM_FAULT_ERROR)) {
-   mmap_read_unlock(mm);
if (fault & VM_FAULT_OOM) {
do_out_of_memory(regs, address);
return;
} else if (fault & VM_FAULT_SIGSEGV) {
-   do_sigsegv(regs, write, address, si_code);
-   return;
+   goto bad_area_nosemaphore;
} else if (fault & 
(VM_FAULT_SIGBUS|VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
do_sigbus(regs, write, address, si_code);
return;
@@ -244,7 +226,11 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
BUG();
}
 
+   return;
+bad_area:
mmap_read_unlock(mm);
+bad_area_nosemaphore:
+   do_sigsegv(regs, write, address, si_code);
 }
 
 asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
-- 
2.27.0



[PATCH rfc -next 05/10] powerpc: mm: use try_vma_locked_page_fault()

2023-07-13 Thread Kefeng Wang
Use new try_vma_locked_page_fault() helper to simplify code.
No functional change intended.

Signed-off-by: Kefeng Wang 
---
 arch/powerpc/mm/fault.c | 54 +
 1 file changed, 22 insertions(+), 32 deletions(-)

diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 82954d0e6906..dd4832a3cf10 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -391,6 +391,23 @@ static int page_fault_is_bad(unsigned long err)
 #define page_fault_is_bad(__err)   ((__err) & DSISR_BAD_FAULT_32S)
 #endif
 
+#ifdef CONFIG_PER_VMA_LOCK
+int arch_vma_check_access(struct vm_area_struct *vma,
+ struct vm_locked_fault *vmlf)
+{
+   int is_exec = TRAP(vmlf->regs) == INTERRUPT_INST_STORAGE;
+   int is_write = page_fault_is_write(vmlf->fault_code);
+
+   if (unlikely(access_pkey_error(is_write, is_exec,
+   (vmlf->fault_code & DSISR_KEYFAULT), vma)))
+   return -EINVAL;
+
+   if (unlikely(access_error(is_write, is_exec, vma)))
+   return -EINVAL;
+   return 0;
+}
+#endif
+
 /*
  * For 600- and 800-family processors, the error_code parameter is DSISR
  * for a data fault, SRR1 for an instruction fault.
@@ -413,6 +430,7 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned 
long address,
int is_write = page_fault_is_write(error_code);
vm_fault_t fault, major = 0;
bool kprobe_fault = kprobe_page_fault(regs, 11);
+   struct vm_locked_fault vmlf;
 
if (unlikely(debugger_fault_handler(regs) || kprobe_fault))
return 0;
@@ -469,41 +487,15 @@ static int ___do_page_fault(struct pt_regs *regs, 
unsigned long address,
if (is_exec)
flags |= FAULT_FLAG_INSTRUCTION;
 
-#ifdef CONFIG_PER_VMA_LOCK
-   if (!(flags & FAULT_FLAG_USER))
-   goto lock_mmap;
-
-   vma = lock_vma_under_rcu(mm, address);
-   if (!vma)
-   goto lock_mmap;
-
-   if (unlikely(access_pkey_error(is_write, is_exec,
-  (error_code & DSISR_KEYFAULT), vma))) {
-   vma_end_read(vma);
-   goto lock_mmap;
-   }
-
-   if (unlikely(access_error(is_write, is_exec, vma))) {
-   vma_end_read(vma);
-   goto lock_mmap;
-   }
-
-   fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, 
regs);
-   if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
-   vma_end_read(vma);
-
-   if (!(fault & VM_FAULT_RETRY)) {
-   count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
+   VM_LOCKED_FAULT_INIT(vmlf, mm, address, flags, 0, regs, error_code);
+   if (try_vma_locked_page_fault(, ))
+   goto retry;
+   else if (!(fault | VM_FAULT_RETRY))
goto done;
-   }
-   count_vm_vma_lock_event(VMA_LOCK_RETRY);
 
if (fault_signal_pending(fault, regs))
return user_mode(regs) ? 0 : SIGBUS;
 
-lock_mmap:
-#endif /* CONFIG_PER_VMA_LOCK */
-
/* When running in the kernel we expect faults to occur only to
 * addresses in user space.  All other faults represent errors in the
 * kernel and should generate an OOPS.  Unfortunately, in the case of an
@@ -552,9 +544,7 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned 
long address,
 
mmap_read_unlock(current->mm);
 
-#ifdef CONFIG_PER_VMA_LOCK
 done:
-#endif
if (unlikely(fault & VM_FAULT_ERROR))
return mm_fault_error(regs, address, fault);
 
-- 
2.27.0



[PATCH rfc -next 06/10] riscv: mm: use try_vma_locked_page_fault()

2023-07-13 Thread Kefeng Wang
Use new try_vma_locked_page_fault() helper to simplify code.
No functional change intended.

Signed-off-by: Kefeng Wang 
---
 arch/riscv/mm/fault.c | 38 +++---
 1 file changed, 15 insertions(+), 23 deletions(-)

diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c
index 6ea2cce4cc17..13bc60370b5c 100644
--- a/arch/riscv/mm/fault.c
+++ b/arch/riscv/mm/fault.c
@@ -215,6 +215,16 @@ static inline bool access_error(unsigned long cause, 
struct vm_area_struct *vma)
return false;
 }
 
+#ifdef CONFIG_PER_VMA_LOCK
+int arch_vma_check_access(struct vm_area_struct *vma,
+ struct vm_locked_fault *vmlf)
+{
+   if (unlikely(access_error(vmlf->fault_code, vma)))
+   return -EINVAL;
+   return 0;
+}
+#endif
+
 /*
  * This routine handles page faults.  It determines the address and the
  * problem, and then passes it off to one of the appropriate routines.
@@ -228,6 +238,7 @@ void handle_page_fault(struct pt_regs *regs)
unsigned int flags = FAULT_FLAG_DEFAULT;
int code = SEGV_MAPERR;
vm_fault_t fault;
+   struct vm_locked_fault vmlf;
 
cause = regs->cause;
addr = regs->badaddr;
@@ -283,35 +294,18 @@ void handle_page_fault(struct pt_regs *regs)
flags |= FAULT_FLAG_WRITE;
else if (cause == EXC_INST_PAGE_FAULT)
flags |= FAULT_FLAG_INSTRUCTION;
-#ifdef CONFIG_PER_VMA_LOCK
-   if (!(flags & FAULT_FLAG_USER))
-   goto lock_mmap;
 
-   vma = lock_vma_under_rcu(mm, addr);
-   if (!vma)
-   goto lock_mmap;
-
-   if (unlikely(access_error(cause, vma))) {
-   vma_end_read(vma);
-   goto lock_mmap;
-   }
-
-   fault = handle_mm_fault(vma, addr, flags | FAULT_FLAG_VMA_LOCK, regs);
-   vma_end_read(vma);
-
-   if (!(fault & VM_FAULT_RETRY)) {
-   count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
+   VM_LOCKED_FAULT_INIT(vmlf, mm, addr, flags, 0, regs, cause);
+   if (try_vma_locked_page_fault(, ))
+   goto retry;
+   else if (!(fault | VM_FAULT_RETRY))
goto done;
-   }
-   count_vm_vma_lock_event(VMA_LOCK_RETRY);
 
if (fault_signal_pending(fault, regs)) {
if (!user_mode(regs))
no_context(regs, addr);
return;
}
-lock_mmap:
-#endif /* CONFIG_PER_VMA_LOCK */
 
 retry:
vma = lock_mm_and_find_vma(mm, addr, regs);
@@ -368,9 +362,7 @@ void handle_page_fault(struct pt_regs *regs)
 
mmap_read_unlock(mm);
 
-#ifdef CONFIG_PER_VMA_LOCK
 done:
-#endif
if (unlikely(fault & VM_FAULT_ERROR)) {
tsk->thread.bad_cause = cause;
mm_fault_error(regs, addr, fault);
-- 
2.27.0



[PATCH rfc -next 02/10] x86: mm: use try_vma_locked_page_fault()

2023-07-13 Thread Kefeng Wang
Use new try_vma_locked_page_fault() helper to simplify code.
No functional change intended.

Signed-off-by: Kefeng Wang 
---
 arch/x86/mm/fault.c | 39 +++
 1 file changed, 15 insertions(+), 24 deletions(-)

diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index 56b4f9faf8c4..3f3b8b0a87de 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -1213,6 +1213,16 @@ do_kern_addr_fault(struct pt_regs *regs, unsigned long 
hw_error_code,
 }
 NOKPROBE_SYMBOL(do_kern_addr_fault);
 
+#ifdef CONFIG_PER_VMA_LOCK
+int arch_vma_check_access(struct vm_area_struct *vma,
+ struct vm_locked_fault *vmlf)
+{
+   if (unlikely(access_error(vmlf->fault_code, vma)))
+   return -EINVAL;
+   return 0;
+}
+#endif
+
 /*
  * Handle faults in the user portion of the address space.  Nothing in here
  * should check X86_PF_USER without a specific justification: for almost
@@ -1231,6 +1241,7 @@ void do_user_addr_fault(struct pt_regs *regs,
struct mm_struct *mm;
vm_fault_t fault;
unsigned int flags = FAULT_FLAG_DEFAULT;
+   struct vm_locked_fault vmlf;
 
tsk = current;
mm = tsk->mm;
@@ -1328,27 +1339,11 @@ void do_user_addr_fault(struct pt_regs *regs,
}
 #endif
 
-#ifdef CONFIG_PER_VMA_LOCK
-   if (!(flags & FAULT_FLAG_USER))
-   goto lock_mmap;
-
-   vma = lock_vma_under_rcu(mm, address);
-   if (!vma)
-   goto lock_mmap;
-
-   if (unlikely(access_error(error_code, vma))) {
-   vma_end_read(vma);
-   goto lock_mmap;
-   }
-   fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, 
regs);
-   if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
-   vma_end_read(vma);
-
-   if (!(fault & VM_FAULT_RETRY)) {
-   count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
+   VM_LOCKED_FAULT_INIT(vmlf, mm, address, flags, 0, regs, error_code);
+   if (try_vma_locked_page_fault(, ))
+   goto retry;
+   else if (!(fault | VM_FAULT_RETRY))
goto done;
-   }
-   count_vm_vma_lock_event(VMA_LOCK_RETRY);
 
/* Quick path to respond to signals */
if (fault_signal_pending(fault, regs)) {
@@ -1358,8 +1353,6 @@ void do_user_addr_fault(struct pt_regs *regs,
 ARCH_DEFAULT_PKEY);
return;
}
-lock_mmap:
-#endif /* CONFIG_PER_VMA_LOCK */
 
 retry:
vma = lock_mm_and_find_vma(mm, address, regs);
@@ -1419,9 +1412,7 @@ void do_user_addr_fault(struct pt_regs *regs,
}
 
mmap_read_unlock(mm);
-#ifdef CONFIG_PER_VMA_LOCK
 done:
-#endif
if (likely(!(fault & VM_FAULT_ERROR)))
return;
 
-- 
2.27.0



[PATCH rfc -next 00/10] mm: convert to generic VMA lock-based page fault

2023-07-13 Thread Kefeng Wang
Add a generic VMA lock-based page fault handler in mm core, and convert
architectures to use it, which eliminate architectures's duplicated codes.

With it, we can avoid multiple changes in architectures's code if we 
add new feature or bugfix.

This fixes riscv missing change about commit 38b3aec8e8d2 "mm: drop per-VMA
lock when returning VM_FAULT_RETRY or VM_FAULT_COMPLETED", and in the end,
we enable this feature on ARM32/Loongarch too.

This is based on next-20230713, only built test(no loongarch compiler,
so except loongarch).

Kefeng Wang (10):
  mm: add a generic VMA lock-based page fault handler
  x86: mm: use try_vma_locked_page_fault()
  arm64: mm: use try_vma_locked_page_fault()
  s390: mm: use try_vma_locked_page_fault()
  powerpc: mm: use try_vma_locked_page_fault()
  riscv: mm: use try_vma_locked_page_fault()
  ARM: mm: try VMA lock-based page fault handling first
  loongarch: mm: cleanup __do_page_fault()
  loongarch: mm: add access_error() helper
  loongarch: mm: try VMA lock-based page fault handling first

 arch/arm/Kconfig  |  1 +
 arch/arm/mm/fault.c   | 15 ++-
 arch/arm64/mm/fault.c | 28 +++-
 arch/loongarch/Kconfig|  1 +
 arch/loongarch/mm/fault.c | 92 ---
 arch/powerpc/mm/fault.c   | 54 ++-
 arch/riscv/mm/fault.c | 38 +++-
 arch/s390/mm/fault.c  | 23 +++---
 arch/x86/mm/fault.c   | 39 +++--
 include/linux/mm.h| 28 
 mm/memory.c   | 42 ++
 11 files changed, 206 insertions(+), 155 deletions(-)

-- 
2.27.0



Re: [PATCH v3 3/7] mm/hotplug: Allow architecture to override memmap on memory support check

2023-07-13 Thread David Hildenbrand

On 12.07.23 22:07, John Hubbard wrote:

On 7/11/23 09:09, David Hildenbrand wrote:
...

Can we make that a __weak function instead?


We can. It is confusing because we do have these two patterns within the kernel 
where we use

#ifndef x
#endif

vs

__weak x

What is the recommended way to override ? I have mostly been using #ifndef for 
most of the arch overrides till now.



I think when placing the implementation in a C file, it's __weak. But don't ask 
me :)

We do this already for arch_get_mappable_range() in mm/memory_hotplug.c and 
IMHO it looks quite nice.



It does look nice. I always forget which parts are supposed to be
__weak, so I went to check Documentation/ , and it was quite
entertaining. There are only two search hits: one trivial reference in
Documentation/conf.py, and the other in checkpatch.rst, which says:

**WEAK_DECLARATION**
  Using weak declarations like __attribute__((weak)) or __weak
  can have unintended link defects.  Avoid using them.

...which seems deeply out of touch with how arch layers work these days,
doesn't it? (This is not rhetorical; I'm asking in order to get an
opinion or two on the topic.)


Did some digging:

commit 65d9a9a60fd71be964effb2e94747a6acb6e7015
Author: Naveen N. Rao 
Date:   Fri Jul 1 13:04:04 2022 +0530

kexec_file: drop weak attribute from functions

As requested

(http://lkml.kernel.org/r/87ee0q7b92@email.froward.int.ebiederm.org),
this series converts weak functions in kexec to use the #ifdef approach.

Quoting the 3e35142ef99fe ("kexec_file: drop weak attribute from

arch_kexec_apply_relocations[_add]") changelog:

: Since commit d1bcae833b32f1 ("ELF: Don't generate unused section symbols")

: [1], binutils (v2.36+) started dropping section symbols that it thought
: were unused.  This isn't an issue in general, but with kexec_file.c, gcc
: is placing kexec_arch_apply_relocations[_add] into a separate
: .text.unlikely section and the section symbol ".text.unlikely" is being
: dropped.  Due to this, recordmcount is unable to find a non-weak symbol in
: .text.unlikely to generate a relocation record against.

This patch (of 2);

Drop __weak attribute from functions in kexec_file.c:

- arch_kexec_kernel_image_probe()
- arch_kimage_file_post_load_cleanup()
- arch_kexec_kernel_image_load()
- arch_kexec_locate_mem_hole()
- arch_kexec_kernel_verify_sig()

arch_kexec_kernel_image_load() calls into kexec_image_load_default(), so

drop the static attribute for the latter.

arch_kexec_kernel_verify_sig() is not overridden by any architecture, so

drop the __weak attribute.

Link: https://lkml.kernel.org/r/cover.1656659357.git.naveen.n@linux.vnet.ibm.com

Link: 
https://lkml.kernel.org/r/2cd7ca1fe4d6bb6ca38e3283c717878388ed6788.1656659357.git.naveen.n@linux.vnet.ibm.com
Signed-off-by: Naveen N. Rao 
Suggested-by: Eric Biederman 
Signed-off-by: Andrew Morton 
Signed-off-by: Mimi Zohar 


So, in general, it's use seems to be fine (unless some tool actually bails out).

https://lore.kernel.org/all/87ee0q7b92@email.froward.int.ebiederm.org/T/#u

Also mentions that__weak and non __weak variants ending up in the vmlinux. Did 
not
check if that's actually (still) the case.

--
Cheers,

David / dhildenb



Re: [PATCH 17/17] perf tests task_analyzer: skip tests if no libtraceevent support

2023-07-13 Thread Aditya Gupta
Hello Ian,

On Wed, Jul 12, 2023 at 06:16:28PM -0700, Ian Rogers wrote:
> On Tue, Jun 13, 2023 at 10:04 AM Athira Rajeev
>  wrote:
> >
> > From: Aditya Gupta 
> >
> > Test "perf script task-analyzer tests" fails in environment with missing
> > libtraceevent support, as perf record fails to create the perf.data
> > file, which further tests depend on.
> >
> > Instead, when perf is not compiled with libtraceevent support, skip those
> > tests instead of failing them, by checking the output of `perf
> > record --dry-run` to see if it prints the error "libtraceevent is
> > necessary for tracepoint support"
> >
> > ...
> >
> > +# check if perf is compiled with libtraceevent support
> > +skip_no_probe_record_support() {
> > +   perf record -e "sched:sched_switch" -a -- sleep 1 2>&1 | grep 
> > "libtraceevent is necessary for tracepoint support" && return 2
> 
> Fwiw, another way to detect build options used in other shell tests is:
> perf version --build-options | grep HAVE_LIBTRACEEVENT | grep -q OFF && 
> return 2
> 
> Thanks,
> Ian
> 

Thanks for the review. That seems more straightforward way to check for
libtraceevent support. I will work on a patch for this, and test it.

Thanks,
Aditya G