[PATCH v3 11/25] mm/memcg: Add folio_memcg, lock_folio_memcg and unlock_folio_memcg

2021-01-27 Thread Matthew Wilcox (Oracle)
The memcontrol code already assumes that page_memcg() will be called
with a non-tail page, so make that more natural by wrapping it with a
folio API.

Signed-off-by: Matthew Wilcox (Oracle) 
---
 include/linux/memcontrol.h | 16 
 mm/memcontrol.c| 36 
 2 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 7a38a1517a05..89aaa22506e6 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -383,6 +383,11 @@ static inline struct mem_cgroup *page_memcg(struct page 
*page)
return (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK);
 }
 
+static inline struct mem_cgroup *folio_memcg(struct folio *folio)
+{
+   return page_memcg(>page);
+}
+
 /*
  * page_memcg_rcu - locklessly get the memory cgroup associated with a page
  * @page: a pointer to the page struct
@@ -869,8 +874,10 @@ void mem_cgroup_print_oom_group(struct mem_cgroup *memcg);
 extern bool cgroup_memory_noswap;
 #endif
 
+struct mem_cgroup *lock_folio_memcg(struct folio *folio);
 struct mem_cgroup *lock_page_memcg(struct page *page);
 void __unlock_page_memcg(struct mem_cgroup *memcg);
+void unlock_folio_memcg(struct folio *folio);
 void unlock_page_memcg(struct page *page);
 
 /*
@@ -1298,6 +1305,11 @@ mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg)
 {
 }
 
+static inline struct mem_cgroup *lock_folio_memcg(struct folio *folio)
+{
+   return NULL;
+}
+
 static inline struct mem_cgroup *lock_page_memcg(struct page *page)
 {
return NULL;
@@ -1307,6 +1319,10 @@ static inline void __unlock_page_memcg(struct mem_cgroup 
*memcg)
 {
 }
 
+static inline void unlock_folio_memcg(struct folio *folio)
+{
+}
+
 static inline void unlock_page_memcg(struct page *page)
 {
 }
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index ed5cc78a8dbf..c3c0c8124b09 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2139,19 +2139,18 @@ void mem_cgroup_print_oom_group(struct mem_cgroup 
*memcg)
 }
 
 /**
- * lock_page_memcg - lock a page and memcg binding
- * @page: the page
+ * lock_folio_memcg - lock a folio and memcg binding
+ * @folio: the folio
  *
- * This function protects unlocked LRU pages from being moved to
+ * This function protects unlocked LRU folios from being moved to
  * another cgroup.
  *
  * It ensures lifetime of the returned memcg. Caller is responsible
- * for the lifetime of the page; __unlock_page_memcg() is available
- * when @page might get freed inside the locked section.
+ * for the lifetime of the folio; __unlock_folio_memcg() is available
+ * when @folio might get freed inside the locked section.
  */
-struct mem_cgroup *lock_page_memcg(struct page *page)
+struct mem_cgroup *lock_folio_memcg(struct folio *folio)
 {
-   struct page *head = compound_head(page); /* rmap on tail pages */
struct mem_cgroup *memcg;
unsigned long flags;
 
@@ -2171,7 +2170,7 @@ struct mem_cgroup *lock_page_memcg(struct page *page)
if (mem_cgroup_disabled())
return NULL;
 again:
-   memcg = page_memcg(head);
+   memcg = folio_memcg(folio);
if (unlikely(!memcg))
return NULL;
 
@@ -2185,7 +2184,7 @@ struct mem_cgroup *lock_page_memcg(struct page *page)
return memcg;
 
spin_lock_irqsave(>move_lock, flags);
-   if (memcg != page_memcg(head)) {
+   if (memcg != folio_memcg(folio)) {
spin_unlock_irqrestore(>move_lock, flags);
goto again;
}
@@ -2200,6 +2199,12 @@ struct mem_cgroup *lock_page_memcg(struct page *page)
 
return memcg;
 }
+EXPORT_SYMBOL(lock_folio_memcg);
+
+struct mem_cgroup *lock_page_memcg(struct page *page)
+{
+   return lock_folio_memcg(page_folio(page));
+}
 EXPORT_SYMBOL(lock_page_memcg);
 
 /**
@@ -,15 +2227,22 @@ void __unlock_page_memcg(struct mem_cgroup *memcg)
rcu_read_unlock();
 }
 
+/**
+ * unlock_folio_memcg - unlock a folio and memcg binding
+ * @folio: the folio
+ */
+void unlock_folio_memcg(struct folio *folio)
+{
+   __unlock_page_memcg(folio_memcg(folio));
+}
+
 /**
  * unlock_page_memcg - unlock a page and memcg binding
  * @page: the page
  */
 void unlock_page_memcg(struct page *page)
 {
-   struct page *head = compound_head(page);
-
-   __unlock_page_memcg(page_memcg(head));
+   unlock_folio_memcg(page_folio(page));
 }
 EXPORT_SYMBOL(unlock_page_memcg);
 
-- 
2.29.2



[PATCH v3 09/25] mm: Add folio_index, folio_page and folio_contains

2021-01-27 Thread Matthew Wilcox (Oracle)
folio_index() is the equivalent of page_index() for folios.  folio_page()
finds the page in a folio for a page cache index.  folio_contains()
tells you whether a folio contains a particular page cache index.

Signed-off-by: Matthew Wilcox (Oracle) 
---
 include/linux/pagemap.h | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 83d24b41fb04..86956e97cd5e 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -447,6 +447,29 @@ static inline bool thp_contains(struct page *head, pgoff_t 
index)
return page_index(head) == (index & ~(thp_nr_pages(head) - 1UL));
 }
 
+static inline pgoff_t folio_index(struct folio *folio)
+{
+if (unlikely(FolioSwapCache(folio)))
+return __page_file_index(>page);
+return folio->page.index;
+}
+
+static inline struct page *folio_page(struct folio *folio, pgoff_t index)
+{
+   index -= folio_index(folio);
+   VM_BUG_ON_FOLIO(index >= folio_nr_pages(folio), folio);
+   return >page + index;
+}
+
+/* Does this folio contain this index? */
+static inline bool folio_contains(struct folio *folio, pgoff_t index)
+{
+   /* HugeTLBfs indexes the page cache in units of hpage_size */
+   if (PageHuge(>page))
+   return folio->page.index == index;
+   return index - folio_index(folio) < folio_nr_pages(folio);
+}
+
 /*
  * Given the page we found in the page cache, return the page corresponding
  * to this index in the file
-- 
2.29.2



[PATCH v3 10/25] mm/util: Add folio_mapping and folio_file_mapping

2021-01-27 Thread Matthew Wilcox (Oracle)
These are the folio equivalent of page_mapping() and page_file_mapping().
Adjust page_file_mapping() and page_mapping_file() to use folios
internally.

Signed-off-by: Matthew Wilcox (Oracle) 
---
 include/linux/mm.h | 23 +++
 mm/swapfile.c  |  6 +++---
 mm/util.c  | 20 ++--
 3 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index d71c5776b571..c6b708007018 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1589,17 +1589,25 @@ void page_address_init(void);
 
 extern void *page_rmapping(struct page *page);
 extern struct anon_vma *page_anon_vma(struct page *page);
-extern struct address_space *page_mapping(struct page *page);
+struct address_space *folio_mapping(struct folio *);
+struct address_space *__folio_file_mapping(struct folio *);
 
-extern struct address_space *__page_file_mapping(struct page *);
+static inline struct address_space *page_mapping(struct page *page)
+{
+   return folio_mapping(page_folio(page));
+}
 
-static inline
-struct address_space *page_file_mapping(struct page *page)
+static inline struct address_space *folio_file_mapping(struct folio *folio)
 {
-   if (unlikely(PageSwapCache(page)))
-   return __page_file_mapping(page);
+   if (unlikely(FolioSwapCache(folio)))
+   return __folio_file_mapping(folio);
 
-   return page->mapping;
+   return folio->page.mapping;
+}
+
+static inline struct address_space *page_file_mapping(struct page *page)
+{
+   return folio_file_mapping(page_folio(page));
 }
 
 extern pgoff_t __page_file_index(struct page *page);
@@ -1616,7 +1624,6 @@ static inline pgoff_t page_index(struct page *page)
 }
 
 bool page_mapped(struct page *page);
-struct address_space *page_mapping(struct page *page);
 struct address_space *page_mapping_file(struct page *page);
 
 /*
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 12a18b896fce..b68e94d5b112 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3551,11 +3551,11 @@ struct swap_info_struct *page_swap_info(struct page 
*page)
 /*
  * out-of-line __page_file_ methods to avoid include hell.
  */
-struct address_space *__page_file_mapping(struct page *page)
+struct address_space *__folio_file_mapping(struct folio *folio)
 {
-   return page_swap_info(page)->swap_file->f_mapping;
+   return page_swap_info(>page)->swap_file->f_mapping;
 }
-EXPORT_SYMBOL_GPL(__page_file_mapping);
+EXPORT_SYMBOL_GPL(__folio_file_mapping);
 
 pgoff_t __page_file_index(struct page *page)
 {
diff --git a/mm/util.c b/mm/util.c
index c37e24d5fa43..c052c39b9f1c 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -686,39 +686,39 @@ struct anon_vma *page_anon_vma(struct page *page)
return __page_rmapping(page);
 }
 
-struct address_space *page_mapping(struct page *page)
+struct address_space *folio_mapping(struct folio *folio)
 {
struct address_space *mapping;
 
-   page = compound_head(page);
-
/* This happens if someone calls flush_dcache_page on slab page */
-   if (unlikely(PageSlab(page)))
+   if (unlikely(FolioSlab(folio)))
return NULL;
 
-   if (unlikely(PageSwapCache(page))) {
+   if (unlikely(FolioSwapCache(folio))) {
swp_entry_t entry;
 
-   entry.val = page_private(page);
+   entry.val = folio_private(folio);
return swap_address_space(entry);
}
 
-   mapping = page->mapping;
+   mapping = folio->page.mapping;
if ((unsigned long)mapping & PAGE_MAPPING_ANON)
return NULL;
 
return (void *)((unsigned long)mapping & ~PAGE_MAPPING_FLAGS);
 }
-EXPORT_SYMBOL(page_mapping);
+EXPORT_SYMBOL(folio_mapping);
 
 /*
  * For file cache pages, return the address_space, otherwise return NULL
  */
 struct address_space *page_mapping_file(struct page *page)
 {
-   if (unlikely(PageSwapCache(page)))
+   struct folio *folio = page_folio(page);
+
+   if (unlikely(FolioSwapCache(folio)))
return NULL;
-   return page_mapping(page);
+   return folio_mapping(folio);
 }
 
 /* Slow path of page_mapcount() for compound pages */
-- 
2.29.2



Re: [abaci-bug...@linux.alibaba.com: [PATCH] s390: Simplify the calculation of variables]

2021-01-27 Thread Vineeth Vijayan

Date: Tue, 26 Jan 2021 17:09:12 +0800
From: Jiapeng Zhong 
To: h...@linux.ibm.com
Cc: , Jiapeng Zhong

Subject: [PATCH] s390: Simplify the calculation of variables
Message-Id: <1611652152-58139-1-git-send-email-abaci-bug...@linux.alibaba.com>
X-Mailer: git-send-email 1.8.3.1

Fix the following coccicheck warnings:

./arch/s390/include/asm/scsw.h:528:48-50: WARNING !A || A && B is
equivalent to !A || B.

Reported-by: Abaci Robot 
Signed-off-by: Jiapeng Zhong 
---
  arch/s390/include/asm/scsw.h | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/s390/include/asm/scsw.h b/arch/s390/include/asm/scsw.h
index c00f7b0..a7c3ccf 100644
--- a/arch/s390/include/asm/scsw.h
+++ b/arch/s390/include/asm/scsw.h
@@ -525,8 +525,7 @@ static inline int scsw_cmd_is_valid_pno(union scsw *scsw)
return (scsw->cmd.fctl != 0) &&
   (scsw->cmd.stctl & SCSW_STCTL_STATUS_PEND) &&
   (!(scsw->cmd.stctl & SCSW_STCTL_INTER_STATUS) ||
-((scsw->cmd.stctl & SCSW_STCTL_INTER_STATUS) &&
- (scsw->cmd.actl & SCSW_ACTL_SUSPENDED)));
+ (scsw->cmd.actl & SCSW_ACTL_SUSPENDED));
  }
  
  /**


Thank you.

Reviewed-by: Vineeth Vijayan 

this will go via next s390-tree upstream-release.

Regards
Vineeth Vijayan.





Re: kprobes broken since 0d00449c7a28 ("x86: Replace ist_enter() with nmi_enter()")

2021-01-27 Thread Nikolay Borisov



On 28.01.21 г. 5:38 ч., Masami Hiramatsu wrote:
> Hi,
> 



> 
> Yeah, there is. Nikolay, could you try this tentative patch?
I can confirm that with this patch everything is working. I also applied
the following diff:

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 6c0018abe68a..cc5a3a18816d 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -96,8 +96,10 @@ unsigned int trace_call_bpf(struct trace_event_call
*call, void *ctx)
 {
unsigned int ret;

-   if (in_nmi()) /* not supported yet */
+   if (in_nmi()) /* not supported yet */ {
+   trace_dump_stack(0);
return 1;
+   }

cant_sleep();



And can confirm that the branch is being hit and the following call
trace is produced:

 => __ftrace_trace_stack
 => trace_call_bpf
 => kprobe_perf_func
 => kprobe_int3_handler
 => exc_int3
 => asm_exc_int3
 => btrfs_sync_file
 => do_fsync
 => __x64_sys_fsync
 => do_syscall_64
 => entry_SYSCALL_64_after_hwframe


> 
> Of course this just drops the NMI check from the handler, so alternative
> checker is required. But I'm not sure what the original code concerns.
> As far as I can see, there seems no re-entrant block flag, nor locks
> among ebpf programs in runtime.
> 
> Alexei, could you tell me what is the concerning situation for bpf?
> 
> Thank you,
> 
> From c5cd0e5f60ef6494c9e1579ec1b82b7344c41f9a Mon Sep 17 00:00:00 2001
> From: Masami Hiramatsu 
> Date: Thu, 28 Jan 2021 12:31:02 +0900
> Subject: [PATCH] tracing: bpf: Remove in_nmi() check from kprobe handler
> 
> Since commit 0d00449c7a28 ("x86: Replace ist_enter() with nmi_enter()") has
> changed the kprobe handler to run in the NMI context, in_nmi() always returns
> true. This means the bpf events on kprobes always skipped.

FWIW I'd prefer if in addition to the original commit you also mention:

ba1f2b2eaa2a ("x86/entry: Fix NMI vs IRQ state tracking")
b6be002bcd1d ("x86/entry: Move nmi entry/exit into common code")

Since they changed the way nmi state is managed in exc_int3 and not in
the original do_int3. THe latter no longer contains any references to
nmi-related code.

> 
> Signed-off-by: Masami Hiramatsu 
> ---
>  kernel/trace/bpf_trace.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 6c0018abe68a..764400260eb6 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -96,9 +96,6 @@ unsigned int trace_call_bpf(struct trace_event_call *call, 
> void *ctx)
>  {
>   unsigned int ret;
>  
> - if (in_nmi()) /* not supported yet */
> - return 1;
> -
>   cant_sleep();
>  
>   if (unlikely(__this_cpu_inc_return(bpf_prog_active) != 1)) {
> 


Re: [PATCH] speakup: Make dectlk flush timeout configurable

2021-01-27 Thread Greg KH
On Thu, Jan 28, 2021 at 12:44:44AM +0100, Samuel Thibault wrote:
> In case the serial port or cable got faulty, we may not be getting
> acknowledgements any more. The driver then currently waits for 4s to
> avoid jamming the device. This makes this delay configurable.
> 
> Signed-off-by: Samuel Thibault 
> ---
>  drivers/accessibility/speakup/speakup_dectlk.c | 11 ++-
>  drivers/accessibility/speakup/spk_types.h  |  3 ++-
>  drivers/accessibility/speakup/synth.c  |  3 +++
>  drivers/accessibility/speakup/varhandlers.c|  1 +
>  4 files changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/accessibility/speakup/speakup_dectlk.c 
> b/drivers/accessibility/speakup/speakup_dectlk.c
> index d75de36..580ec79 100644
> --- a/drivers/accessibility/speakup/speakup_dectlk.c
> +++ b/drivers/accessibility/speakup/speakup_dectlk.c
> @@ -78,6 +78,8 @@ static struct kobj_attribute direct_attribute =
>   __ATTR(direct, 0644, spk_var_show, spk_var_store);
>  static struct kobj_attribute full_time_attribute =
>   __ATTR(full_time, 0644, spk_var_show, spk_var_store);
> +static struct kobj_attribute flush_time_attribute =
> + __ATTR(flush_time, 0644, spk_var_show, spk_var_store);

__ATTR_RW()?

Also, no Documentation/ABI/ update for the new one user-visable
attribute?  Please fix up.

thanks,

greg k-h


[RFC PATCH 00/34] block: introduce bio_new()

2021-01-27 Thread Chaitanya Kulkarni
Hi,

This is a *compile only RFC* which adds a generic helper to initialize
the various fields of the bio that is repeated all the places in
file-systems, block layer, and drivers.

The new helper allows callers to initialize non-optional members of bio
such as bdev, sector, op, opflags, max_bvecs and gfp_mask by
encapsulating new bio allocation with bio alloc with initialization
at one place.

The objective of this RFC is to only start a discussion, this it not 
completely tested at all.

-ck 

Chaitanya Kulkarni (34):
  block: move common code into blk_next_bio()
  block: introduce and use bio_new
  drdb: use bio_new in drdb
  drdb: use bio_new() in submit_one_flush
  xen-blkback: use bio_new
  zram: use bio_new
  dm: use bio_new in dm-log-writes
  dm-zoned: use bio_new in get_mblock_slow
  dm-zoned: use bio_new in dmz_write_mblock
  dm-zoned: use bio_new in dmz_rdwr_block
  nvmet: use bio_new in nvmet_bdev_execute_rw
  scsi: target/iblock: use bio_new
  block: use bio_new in __blkdev_direct_IO
  fs/buffer: use bio_new in submit_bh_wbc
  fscrypt: use bio_new in fscrypt_zeroout_range
  fs/direct-io: use bio_new in dio_bio_alloc
  iomap: use bio_new in iomap_dio_zero
  iomap: use bio_new in iomap_dio_bio_actor
  fs/jfs/jfs_logmgr.c: use bio_new in lbmRead
  fs/jfs/jfs_logmgr.c: use bio_new in lbmStartIO
  fs/jfs/jfs_metapage.c: use bio_new in metapage_writepage
  fs/jfs/jfs_metapage.c: use bio_new in metapage_readpage
  fs/mpage.c: use bio_new mpage_alloc
  fs/nilfs: use bio_new nilfs_alloc_seg_bio
  ocfs/cluster: use bio_new in dm-log-writes
  xfs: use bio_new in xfs_rw_bdev
  xfs: use bio_new in xfs_buf_ioapply_map
  zonefs: use bio_new
  power/swap: use bio_new in hib_submit_io
  hfsplus: use bio_new in hfsplus_submit_bio()
  iomap: use bio_new in iomap_readpage_actor
  mm: use bio_new in __swap_writepage
  mm: use bio_new in swap_readpage
  mm: add swap_bio_new common bio helper

 block/blk-lib.c | 34 ++---
 block/blk-zoned.c   |  4 +---
 block/blk.h |  5 +++--
 drivers/block/drbd/drbd_receiver.c  | 12 +-
 drivers/block/xen-blkback/blkback.c | 20 +++--
 drivers/block/zram/zram_drv.c   |  5 ++---
 drivers/md/dm-log-writes.c  | 30 +
 drivers/md/dm-zoned-metadata.c  | 18 +--
 drivers/nvme/target/io-cmd-bdev.c   |  9 +++-
 drivers/target/target_core_iblock.c |  5 ++---
 fs/block_dev.c  |  6 ++---
 fs/buffer.c | 16 ++
 fs/crypto/bio.c |  5 ++---
 fs/direct-io.c  |  6 ++---
 fs/hfsplus/wrapper.c|  5 +
 fs/iomap/buffered-io.c  | 12 +-
 fs/iomap/direct-io.c| 11 --
 fs/jfs/jfs_logmgr.c | 13 ---
 fs/jfs/jfs_metapage.c   | 15 +
 fs/mpage.c  | 18 +--
 fs/nilfs2/segbuf.c  | 10 ++---
 fs/ocfs2/cluster/heartbeat.c|  6 ++---
 fs/xfs/xfs_bio_io.c |  7 ++
 fs/xfs/xfs_buf.c|  6 ++---
 fs/zonefs/super.c   |  6 ++---
 include/linux/bio.h | 25 +
 kernel/power/swap.c |  7 +++---
 mm/page_io.c| 30 +
 28 files changed, 151 insertions(+), 195 deletions(-)

-- 
2.22.1



[RFC PATCH 05/34] xen-blkback: use bio_new

2021-01-27 Thread Chaitanya Kulkarni
Create a wrapper on the tio of the bio_new() named get_new_bio() & use
it in the dispatch_rw_block_io().
p
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/block/xen-blkback/blkback.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/block/xen-blkback/blkback.c 
b/drivers/block/xen-blkback/blkback.c
index 9ebf53903d7b..3760278f0ee6 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -1174,6 +1174,15 @@ do_block_io_op(struct xen_blkif_ring *ring, unsigned int 
*eoi_flags)
 
return more_to_do;
 }
+
+static struct bio *
+get_new_bio(struct phys_req *preq, unsigned int op, unsigned int op_flags,
+   gfp_t gfp_mask, unsigned int nr_bvec)
+{
+   return bio_new(preq->bdev, preq->sector_number, op, op_flags, nr_bvec,
+  gfp_mask);
+
+}
 /*
  * Transmutation of the 'struct blkif_request' to a proper 'struct bio'
  * and call the 'submit_bio' to pass it to the underlying storage.
@@ -1324,16 +1333,14 @@ static int dispatch_rw_block_io(struct xen_blkif_ring 
*ring,
 seg[i].offset) == 0)) {
 
int nr_iovecs = min_t(int, (nseg-i), BIO_MAX_PAGES);
-   bio = bio_alloc(GFP_KERNEL, nr_iovecs);
+   bio = get_new_bio(, operation, operation_flags,
+ GFP_KERNEL, nr_iovecs);
if (unlikely(bio == NULL))
goto fail_put_bio;
 
biolist[nbio++] = bio;
-   bio_set_dev(bio, preq.bdev);
bio->bi_private = pending_req;
bio->bi_end_io  = end_block_io_op;
-   bio->bi_iter.bi_sector  = preq.sector_number;
-   bio_set_op_attrs(bio, operation, operation_flags);
}
 
preq.sector_number += seg[i].nsec;
@@ -1343,15 +1350,14 @@ static int dispatch_rw_block_io(struct xen_blkif_ring 
*ring,
if (!bio) {
BUG_ON(operation_flags != REQ_PREFLUSH);
 
-   bio = bio_alloc(GFP_KERNEL, 0);
+   bio = get_new_bio(, operation, operation_flags,
+ GFP_KERNEL, 0);
if (unlikely(bio == NULL))
goto fail_put_bio;
 
biolist[nbio++] = bio;
-   bio_set_dev(bio, preq.bdev);
bio->bi_private = pending_req;
bio->bi_end_io  = end_block_io_op;
-   bio_set_op_attrs(bio, operation, operation_flags);
}
 
atomic_set(_req->pendcnt, nbio);
-- 
2.22.1



Re: [workqueue] d5bff968ea: WARNING:at_kernel/workqueue.c:#process_one_work

2021-01-27 Thread Xing Zhengjun



On 1/27/2021 5:21 PM, Hillf Danton wrote:

On Wed, 27 Jan 2021 16:04:25 +0800 Xing Zhengjun wrote:

On 1/26/2021 3:39 PM, Hillf Danton wrote:

On 26 Jan 2021 10:45:21 +0800 Xing Zhengjun wrote:

On 1/25/2021 5:29 PM, Hillf Danton wrote:

On 25 Jan 2021 16:31:32 +0800 Xing Zhengjun wrote:

On 1/22/2021 3:59 PM, Hillf Danton wrote:

On Fri, 22 Jan 2021 09:48:32 +0800 Xing Zhengjun wrote:

On 1/21/2021 12:00 PM, Hillf Danton wrote:

On Wed, 20 Jan 2021 21:46:33 +0800 Oliver Sang wrote:

On Fri, Jan 15, 2021 at 03:24:32PM +0800, Hillf Danton wrote:

Thu, 14 Jan 2021 15:45:11 +0800


FYI, we noticed the following commit (built with gcc-9):

commit: d5bff968ea9cc005e632d9369c26cbd8148c93d5 ("workqueue: break affinity 
initiatively")
https://git.kernel.org/cgit/linux/kernel/git/paulmck/linux-rcu.git 
dev.2021.01.11b


[...]


[   73.794288] WARNING: CPU: 0 PID: 22 at kernel/workqueue.c:2192 
process_one_work


Thanks for your report.

We can also break CPU affinity by checking POOL_DISASSOCIATED at attach
time without extra cost paid; that way we have the same behavior as at
the unbind time.

What is more the change that makes kworker pcpu is cut because they are
going to not help either hotplug or the mechanism of stop machine.


hi, by applying below patch, the issue still happened.


Thanks for your report.


[ 4.574467] pci :00:00.0: Limiting direct PCI/PCI transfers
[ 4.575651] pci :00:01.0: Activating ISA DMA hang workarounds
[ 4.576900] pci :00:02.0: Video device with shadowed ROM at [mem 
0x000c-0x000d]
[ 4.578648] PCI: CLS 0 bytes, default 64
[ 4.579685] Unpacking initramfs...
[ 8.878031] ---[ cut here ]---
[ 8.879083] WARNING: CPU: 0 PID: 22 at kernel/workqueue.c:2187 
process_one_work+0x92/0x9e0
[ 8.880688] Modules linked in:
[ 8.881274] CPU: 0 PID: 22 Comm: kworker/1:0 Not tainted 
5.11.0-rc3-gc213503139bb #2


The kworker bond to CPU1 runs on CPU0 and triggers the warning, which
shows that scheduler breaks CPU affinity, after 06249738a41a
("workqueue: Manually break affinity on hotplug"), though quite likely
by kworker/1:0 for the initial workers.


[ 8.882518] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
1.12.0-1 04/01/2014
[ 8.887539] Workqueue: 0x0 (events)
[ 8.887838] EIP: process_one_work+0x92/0x9e0
[ 8.887838] Code: 37 64 a1 58 54 4c 43 39 45 24 74 2c 31 c9 ba 01 00 00 00 c7 04 24 
01 00 00 00 b8 08 1d f5 42 e8 74 85 13 00 ff 05 b8 30 04 43 <0f> 0b ba 01 00 00 
00 eb 22 8d 74 26 00 90 c7 04 24 01 00 00 00 31
[ 8.887838] EAX: 42f51d08 EBX:  ECX:  EDX: 0001
[ 8.887838] ESI: 43c04720 EDI: 42e45620 EBP: de7f23c0 ESP: 43d7bf08
[ 8.887838] DS: 007b ES: 007b FS: 00d8 GS:  SS: 0068 EFLAGS: 00010002
[ 8.887838] CR0: 80050033 CR2:  CR3: 034e3000 CR4: 000406d0
[ 8.887838] Call Trace:
[ 8.887838] ? worker_thread+0x98/0x6a0
[ 8.887838] ? worker_thread+0x2dd/0x6a0
[ 8.887838] ? kthread+0x1ba/0x1e0
[ 8.887838] ? create_worker+0x1e0/0x1e0
[ 8.887838] ? kzalloc+0x20/0x20
[ 8.887838] ? ret_from_fork+0x1c/0x28
[ 8.887838] _warn_unseeded_randomness: 63 callbacks suppressed
[ 8.887838] random: get_random_bytes called from init_oops_id+0x2b/0x60 with 
crng_init=0
[ 8.887838] --[ end trace ac461b4d54c37cfa ]--



Instead of creating the initial workers only on the active CPUS, rebind
them (labeled pcpu) and jump to the right CPU at bootup time.

--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2385,6 +2385,16 @@ woke_up:
return 0;
}
  
+	if (!(pool->flags & POOL_DISASSOCIATED) && smp_processor_id() !=

+   pool->cpu) {
+   /* scheduler breaks CPU affinity for us, rebind it */
+   raw_spin_unlock_irq(>lock);
+   set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask);
+   /* and jump to the right seat */
+   schedule_timeout_interruptible(1);
+   goto woke_up;
+   }
+
worker_leave_idle(worker);
  recheck:
/* no more worker necessary? */
--


I test the patch, the warning still appears in the kernel log.


Thanks for your report.


[  230.356503] smpboot: CPU 1 is now offline
[  230.544652] x86: Booting SMP configuration:
[  230.545077] smpboot: Booting Node 0 Processor 1 APIC 0x1
[  230.545640] kvm-clock: cpu 1, msr 34f6021, secondary cpu clock
[  230.545675] masked ExtINT on CPU#1
[  230.593829] [ cut here ]
[  230.594257] WARNING: CPU: 0 PID: 257 at kernel/workqueue.c:2192 
process_one_work+0x92/0x9e0
[  230.594990] Modules linked in: rcutorture torture mousedev input_leds
led_class pcspkr psmouse evbug tiny_power_button button
[  230.595961] CPU: 0 PID: 257 Comm: kworker/1:3 Not tainted 
5.11.0-rc3-gdcba55d9080f #2


Like what was reported, kworker bond to CPU1 runs on CPU0 and triggers
warning, due to scheduler breaking CPU affinity for us. What is new, the
affinity was broken at offline time instead of bootup.


[  

Re: [PATCH v4 2/4] mm: failfast mode with __GFP_NORETRY in alloc_contig_range

2021-01-27 Thread Michal Hocko
On Wed 27-01-21 12:42:45, Minchan Kim wrote:
> On Tue, Jan 26, 2021 at 08:44:49AM +0100, Michal Hocko wrote:
> > On Mon 25-01-21 11:33:36, Minchan Kim wrote:
> > > On Mon, Jan 25, 2021 at 02:12:00PM +0100, Michal Hocko wrote:
> > > > On Thu 21-01-21 09:55:00, Minchan Kim wrote:
> > > > > Contiguous memory allocation can be stalled due to waiting
> > > > > on page writeback and/or page lock which causes unpredictable
> > > > > delay. It's a unavoidable cost for the requestor to get *big*
> > > > > contiguous memory but it's expensive for *small* contiguous
> > > > > memory(e.g., order-4) because caller could retry the request
> > > > > in different range where would have easy migratable pages
> > > > > without stalling.
> > > > > 
> > > > > This patch introduce __GFP_NORETRY as compaction gfp_mask in
> > > > > alloc_contig_range so it will fail fast without blocking
> > > > > when it encounters pages needed waiting.
> > > > 
> > > > I am not against controling how hard this allocator tries with gfp mask
> > > > but this changelog is rather void on any data and any user.
> > > > 
> > > > It is also rather dubious to have retries when then caller says to not
> > > > retry.
> > > 
> > > Since max_tries is 1 with ++tries, it shouldn't retry.
> > 
> > OK, I have missed that. This is a tricky code. ASYNC mode should be
> > completely orthogonal to the retries count. Those are different things.
> > Page allocator does an explicit bail out based on __GFP_NORETRY. You
> > should be doing the same.
> 
> Before sending next revision, let me check this part again.
> 
> I want to use __GFP_NORETRY to indicate "opportunistic-easy-to-fail attempt"
> and I want to use ASYNC migrate_mode to help the goal.
> 
> Do you see the problem?

No, as I've said. This is a normal NORETRY policy. And ASYNC migration
is a mere implementation detail you do not have bother your users about.
This is the semantic view. From the implementation POV it should be the
gfp mask to drive decisions rather than a random (ASYNC) flag to control
retries as you did here.

-- 
Michal Hocko
SUSE Labs


Re: [PATCH V3] mtd: rawnand: qcom: update last code word register

2021-01-27 Thread Manivannan Sadhasivam
On Sun, Jan 10, 2021 at 09:31:45AM +0530, Md Sadre Alam wrote:
> From QPIC version 2.0 onwards new register got added to
> read last codeword. This change will update the same.
> 
> For first three code word READ_LOCATION_n register will be
> use.For last code word READ_LOCATION_LAST_CW_n register will be
> use.
> 
> Signed-off-by: Md Sadre Alam 

I gave this patch a try on SDX55 board but not able to resolve an issue and
I think it is related to reading the last code word which this patch is trying
to address. For my patch on supporting QPIC v2 IP, I tested with SDX55-MTP board
and I never hit any issue. But on my new dev board (Telit FN980), there seems to
be an issue while populating the partitions and tracing down that bug lands me
in copy_last_cw() function.

The issue only happens while creating the 3rd partition on Telit board whose
size differs when compared with MTP. The board just reboots into QDL mode
whenever it tries to read the last code word.

Below is the snippet of partition layout:

Telit partitions:

[1.082015] 0: sbl offs=0x size=0x000a attr:0x00ff
[1.082702] 1: mibib offs=0x000a size=0x000a attr:0x00ff
[1.083488] 2: ico offs=0x0014 size=0x0014 attr:0x00ff
[1.084572] 3: efs2 offs=0x0028 size=0x002c attr:0x00ff
[1.085316] 4: tz offs=0x0054 size=0x0007 attr:0x00ff
[1.086089] 5: tz_devcfg offs=0x005b size=0x0004 attr:0x00ff


MTP partitions:

[1.573871] 0: sbl offs=0x size=0x000a attr:0x00ff
[1.581139] 1: mibib offs=0x000a size=0x000a attr:0x00ff
[1.587362] 2: efs2 offs=0x0014 size=0x002c attr:0x00ff
[1.593853] 3: tz offs=0x0040 size=0x0007 attr:0x00ff
[1.599860] 4: tz_devcfg offs=0x0047 size=0x0004 attr:0x00ff
...

So until I figure this out, please keep this patch on hold!

Thanks,
Mani

> ---
> [V3]
>  * Added else condition for last code word in update_rw_regs().
>  drivers/mtd/nand/raw/qcom_nandc.c | 84 
> ---
>  1 file changed, 70 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/qcom_nandc.c 
> b/drivers/mtd/nand/raw/qcom_nandc.c
> index 667e4bf..50ff6e3 100644
> --- a/drivers/mtd/nand/raw/qcom_nandc.c
> +++ b/drivers/mtd/nand/raw/qcom_nandc.c
> @@ -48,6 +48,10 @@
>  #define  NAND_READ_LOCATION_10xf24
>  #define  NAND_READ_LOCATION_20xf28
>  #define  NAND_READ_LOCATION_30xf2c
> +#define  NAND_READ_LOCATION_LAST_CW_00xf40
> +#define  NAND_READ_LOCATION_LAST_CW_10xf44
> +#define  NAND_READ_LOCATION_LAST_CW_20xf48
> +#define  NAND_READ_LOCATION_LAST_CW_30xf4c
>  
>  /* dummy register offsets, used by write_reg_dma */
>  #define  NAND_DEV_CMD1_RESTORE   0xdead
> @@ -187,6 +191,12 @@ nandc_set_reg(nandc, NAND_READ_LOCATION_##reg,   
> \
> ((size) << READ_LOCATION_SIZE) |  \
> ((is_last) << READ_LOCATION_LAST))
>  
> +#define nandc_set_read_loc_last(nandc, reg, offset, size, is_last)   \
> +nandc_set_reg(nandc, NAND_READ_LOCATION_LAST_CW_##reg,   
> \
> +   ((offset) << READ_LOCATION_OFFSET) |  \
> +   ((size) << READ_LOCATION_SIZE) |  \
> +   ((is_last) << READ_LOCATION_LAST))
> +
>  /*
>   * Returns the actual register address for all NAND_DEV_ registers
>   * (i.e. NAND_DEV_CMD0, NAND_DEV_CMD1, NAND_DEV_CMD2 and NAND_DEV_CMD_VLD)
> @@ -316,6 +326,10 @@ struct nandc_regs {
>   __le32 read_location1;
>   __le32 read_location2;
>   __le32 read_location3;
> + __le32 read_location_last0;
> + __le32 read_location_last1;
> + __le32 read_location_last2;
> + __le32 read_location_last3;
>  
>   __le32 erased_cw_detect_cfg_clr;
>   __le32 erased_cw_detect_cfg_set;
> @@ -644,6 +658,14 @@ static __le32 *offset_to_nandc_reg(struct nandc_regs 
> *regs, int offset)
>   return >read_location2;
>   case NAND_READ_LOCATION_3:
>   return >read_location3;
> + case NAND_READ_LOCATION_LAST_CW_0:
> + return >read_location_last0;
> + case NAND_READ_LOCATION_LAST_CW_1:
> + return >read_location_last1;
> + case NAND_READ_LOCATION_LAST_CW_2:
> + return >read_location_last2;
> + case NAND_READ_LOCATION_LAST_CW_3:
> + return >read_location_last3;
>   default:
>   return NULL;
>   }
> @@ -719,9 +741,14 @@ static void update_rw_regs(struct qcom_nand_host *host, 
> int num_cw, bool read)
>   nandc_set_reg(nandc, NAND_READ_STATUS, host->clrreadstatus);
>   nandc_set_reg(nandc, NAND_EXEC_CMD, 1);
>  
> - if (read)
> - nandc_set_read_loc(nandc, 0, 0, host->use_ecc ?
> -host->cw_data : host->cw_size, 1);
> + if (read) {
> + if (nandc->props->qpic_v2)

Re: [PATCH] USB: serial: option: Adding support for Cinterion MV31

2021-01-27 Thread Johan Hovold
On Wed, Jan 27, 2021 at 08:58:46PM +0100, Christoph Schemmel wrote:
> Adding support for Cinterion device MV31 for enumeration with
> PID 0x00B3 and 0x00B7.
> 
> usb-devices output for 0x00B3
> T:  Bus=04 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  6 Spd=5000 MxCh= 0
> D:  Ver= 3.20 Cls=ef(misc ) Sub=02 Prot=01 MxPS= 9 #Cfgs=  1
> P:  Vendor=1e2d ProdID=00b3 Rev=04.14
> S:  Manufacturer=Cinterion
> S:  Product=Cinterion PID 0x00B3 USB Mobile Broadband
> S:  SerialNumber=b3246eed
> C:  #Ifs= 6 Cfg#= 1 Atr=a0 MxPwr=896mA
> I:  If#=0x0 Alt= 0 #EPs= 1 Cls=02(commc) Sub=0e Prot=00 Driver=cdc_mbim
> I:  If#=0x1 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=02 Driver=cdc_mbim
> I:  If#=0x2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
> I:  If#=0x3 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=ff Prot=ff Driver=cdc_wdm
> I:  If#=0x4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
> I:  If#=0x5 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=30 Driver=option
> 
> usb-devices output for 0x00B7
> T:  Bus=04 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  5 Spd=5000 MxCh= 0
> D:  Ver= 3.20 Cls=ef(misc ) Sub=02 Prot=01 MxPS= 9 #Cfgs=  1
> P:  Vendor=1e2d ProdID=00b7 Rev=04.14
> S:  Manufacturer=Cinterion
> S:  Product=Cinterion PID 0x00B3 USB Mobile Broadband
> S:  SerialNumber=b3246eed
> C:  #Ifs= 4 Cfg#= 1 Atr=a0 MxPwr=896mA
> I:  If#=0x0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=qmi_wwan
> I:  If#=0x1 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
> I:  If#=0x2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
> I:  If#=0x3 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=30 Driver=option
> 
> Signed-off-by: Christoph Schemmel 

Perfect, thanks for resending. Now applied.

Johan


Re: [PATCH v11 3/9] drm/mediatek: add RDMA fifo size error handle

2021-01-27 Thread CK Hu
Hi, Hsin-Yi:

On Thu, 2021-01-28 at 15:27 +0800, Hsin-Yi Wang wrote:
> From: Yongqiang Niu 
> 
> This patch add RDMA fifo size error handle
> rdma fifo size will not always bigger than the calculated threshold
> if that case happened, we need set fifo size as the threshold
> 
> Signed-off-by: Yongqiang Niu 
> Signed-off-by: Hsin-Yi Wang 
> ---
>  drivers/gpu/drm/mediatek/mtk_disp_rdma.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c 
> b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
> index b84004394970f..04b9542010b00 100644
> --- a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
> +++ b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
> @@ -168,6 +168,10 @@ void mtk_rdma_config(struct device *dev, unsigned int 
> width,
>* account for blanking, and with a pixel depth of 4 bytes:
>*/
>   threshold = width * height * vrefresh * 4 * 7 / 100;
> +
> + if (threshold > rdma_fifo_size)
> + threshold = rdma_fifo_size;
> +

Please see the discussion in [1].

[1]
https://patchwork.kernel.org/project/linux-mediatek/patch/1607591262-21736-6-git-send-email-yongqiang@mediatek.com/

Regards,
CK

>   reg = RDMA_FIFO_UNDERFLOW_EN |
> RDMA_FIFO_PSEUDO_SIZE(rdma_fifo_size) |
> RDMA_OUTPUT_VALID_FIFO_THRESHOLD(threshold);



[RFC PATCH 06/34] zram: use bio_new

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/block/zram/zram_drv.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index d7018543842e..5d744e528d4f 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -587,12 +587,11 @@ static int read_from_bdev_async(struct zram *zram, struct 
bio_vec *bvec,
 {
struct bio *bio;
 
-   bio = bio_alloc(GFP_ATOMIC, 1);
+   bio = bio_alloc(zram->bdev, entry * (PAGE_SIZE >> 9), 0, 0,
+   1, GFP_ATOMIC);
if (!bio)
return -ENOMEM;
 
-   bio->bi_iter.bi_sector = entry * (PAGE_SIZE >> 9);
-   bio_set_dev(bio, zram->bdev);
if (!bio_add_page(bio, bvec->bv_page, bvec->bv_len, bvec->bv_offset)) {
bio_put(bio);
return -EIO;
-- 
2.22.1



[PATCH v2] kdb: kdb_support: Fix debugging information problem

2021-01-27 Thread Stephen Zhang
There are several common patterns.

0:
kdb_printf("...",...);

which is the normal one.

1:
kdb_printf("%s: "...,__func__,...)

We could improve '1' to this :

#define kdb_func_printf(format, args...) \
   kdb_printf("%s: " format, __func__, ## args)

2:
if(KDB_DEBUG(AR))
kdb_printf("%s "...,__func__,...);

We could improve '2' to this :
#define kdb_dbg_printf(mask, format, args...) \
   do { \
if (KDB_DEBUG(mask)) \
kdb_func_printf(format, ## 
args); \
   } while (0)

In additon, we changed the format code of size_t to %zu.

Signed-off-by: Stephen Zhang 
---
v1->v2 Changelog:
- Add 'mask' parameter in kdb_dbg_printf()

Thanks to Daniel and Doug's suggestions and review.

 kernel/debug/kdb/kdb_private.h | 10 
 kernel/debug/kdb/kdb_support.c | 56 +++---
 2 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/kernel/debug/kdb/kdb_private.h b/kernel/debug/kdb/kdb_private.h
index a4281fb..0a56d35 100644
--- a/kernel/debug/kdb/kdb_private.h
+++ b/kernel/debug/kdb/kdb_private.h
@@ -254,4 +254,14 @@ extern unsigned long kdb_task_state(const struct 
task_struct *p,
 #defineKDB_WORD_SIZE   ((int)sizeof(unsigned long))
 
 #endif /* CONFIG_KGDB_KDB */
+
+#define kdb_func_printf(format, args...) \
+   kdb_printf("%s: " format, __func__, ## args)
+
+#define kdb_dbg_printf(mask, format, args...) \
+   do { \
+   if (KDB_DEBUG(mask)) \
+   kdb_func_printf(format, ## args); \
+   } while (0)
+
 #endif /* !_KDBPRIVATE_H */
diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c
index 6226502..0f6fc77 100644
--- a/kernel/debug/kdb/kdb_support.c
+++ b/kernel/debug/kdb/kdb_support.c
@@ -39,20 +39,17 @@
  */
 int kdbgetsymval(const char *symname, kdb_symtab_t *symtab)
 {
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbgetsymval: symname=%s, symtab=%px\n", symname,
-  symtab);
+   kdb_dbg_printf(AR, "symname=%s, symtab=%px\n", symname,
+   symtab);
memset(symtab, 0, sizeof(*symtab));
symtab->sym_start = kallsyms_lookup_name(symname);
if (symtab->sym_start) {
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbgetsymval: returns 1, "
-  "symtab->sym_start=0x%lx\n",
-  symtab->sym_start);
+   kdb_dbg_printf(AR, "returns 1, "
+   "symtab->sym_start=0x%lx\n",
+   symtab->sym_start);
return 1;
}
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbgetsymval: returns 0\n");
+   kdb_dbg_printf(AR, "returns 0\n");
return 0;
 }
 EXPORT_SYMBOL(kdbgetsymval);
@@ -87,15 +84,14 @@ int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab)
 #define knt1_size 128  /* must be >= kallsyms table size */
char *knt1 = NULL;
 
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbnearsym: addr=0x%lx, symtab=%px\n", addr, 
symtab);
+   kdb_dbg_printf(AR, "addr=0x%lx, symtab=%px\n", addr, symtab);
memset(symtab, 0, sizeof(*symtab));
 
if (addr < 4096)
goto out;
knt1 = debug_kmalloc(knt1_size, GFP_ATOMIC);
if (!knt1) {
-   kdb_printf("kdbnearsym: addr=0x%lx cannot kmalloc knt1\n",
+   kdb_func_printf("addr=0x%lx cannot kmalloc knt1\n",
   addr);
goto out;
}
@@ -147,11 +143,10 @@ int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab)
 
if (symtab->mod_name == NULL)
symtab->mod_name = "kernel";
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbnearsym: returns %d symtab->sym_start=0x%lx, "
-  "symtab->mod_name=%px, symtab->sym_name=%px (%s)\n", ret,
-  symtab->sym_start, symtab->mod_name, symtab->sym_name,
-  symtab->sym_name);
+   kdb_dbg_printf(AR, "returns %d symtab->sym_start=0x%lx, "
+   "symtab->mod_name=%px, symtab->sym_name=%px (%s)\n", ret,
+   symtab->sym_start, symtab->mod_name, symtab->sym_name,
+   symtab->sym_name);
 
 out:
debug_kfree(knt1);
@@ -328,7 +323,7 @@ int kdb_getarea_size(void *res, unsigned long addr, size_t 
size)
int ret = copy_from_kernel_nofault((char *)res, (char *)addr, size);
if (ret) {
if (!KDB_STATE(SUPPRESS)) {
-   kdb_printf("kdb_getarea: Bad address 0x%lx\n", addr);
+   kdb_func_printf("Bad address 0x%lx\n", addr);
KDB_STATE_SET(SUPPRESS);
}
ret = KDB_BADADDR;
@@ -353,7 +348,7 @@ int kdb_putarea_size(unsigned long addr, void *res, size_t 
size)
  

[PATCH] opp: Allow lazy-linking of required-opps

2021-01-27 Thread Viresh Kumar
The OPP core currently requires the required opp tables to be available
before the dependent OPP table is added, as it needs to create links
from the dependent OPP table to the required ones. This may not be
convenient for all the platforms though, as this requires strict
ordering for probing the drivers.

This patch allows lazy-linking of the required-opps. The OPP tables for
which the required-opp-tables aren't available at the time of their
initialization, are added to a special list of OPP tables:
lazy_opp_tables. Later on, whenever a new OPP table is registered with
the OPP core, we check if it is required by an OPP table in the pending
list; if yes, then we complete the linking then and there.

An OPP table is marked unusable until the time all its required-opp
tables are available. And if lazy-linking fails for an OPP table, the
OPP core disables all of its OPPs to make sure no one can use them.

Tested-by: Hsin-Yi Wang 
Signed-off-by: Viresh Kumar 
---
 drivers/opp/core.c |  45 +
 drivers/opp/of.c   | 122 +++--
 drivers/opp/opp.h  |  10 +++-
 3 files changed, 161 insertions(+), 16 deletions(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 6958a5cd2fd8..e03600547b98 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -27,6 +27,10 @@
  * various states of availability.
  */
 LIST_HEAD(opp_tables);
+
+/* OPP tables with uninitialized required OPPs */
+LIST_HEAD(lazy_opp_tables);
+
 /* Lock to allow exclusive modification to the device and opp lists */
 DEFINE_MUTEX(opp_table_lock);
 /* Flag indicating that opp_tables list is being updated at the moment */
@@ -163,6 +167,10 @@ unsigned int dev_pm_opp_get_required_pstate(struct 
dev_pm_opp *opp,
return 0;
}
 
+   /* required-opps not fully initialized yet */
+   if (lazy_linking_pending(opp->opp_table))
+   return 0;
+
return opp->required_opps[index]->pstate;
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_get_required_pstate);
@@ -885,6 +893,10 @@ static int _set_required_opps(struct device *dev,
if (!required_opp_tables)
return 0;
 
+   /* required-opps not fully initialized yet */
+   if (lazy_linking_pending(opp_table))
+   return -EBUSY;
+
/* Single genpd case */
if (!genpd_virt_devs)
return _set_required_opp(dev, dev, opp, 0);
@@ -1181,6 +1193,7 @@ static struct opp_table *_allocate_opp_table(struct 
device *dev, int index)
mutex_init(_table->lock);
mutex_init(_table->genpd_virt_dev_lock);
INIT_LIST_HEAD(_table->dev_list);
+   INIT_LIST_HEAD(_table->lazy);
 
/* Mark regulator count uninitialized */
opp_table->regulator_count = -1;
@@ -1632,6 +1645,21 @@ static int _opp_is_duplicate(struct device *dev, struct 
dev_pm_opp *new_opp,
return 0;
 }
 
+void _required_opps_available(struct dev_pm_opp *opp, int count)
+{
+   int i;
+
+   for (i = 0; i < count; i++) {
+   if (opp->required_opps[i]->available)
+   continue;
+
+   opp->available = false;
+   pr_warn("%s: OPP not supported by required OPP %pOF (%lu)\n",
+__func__, opp->required_opps[i]->np, opp->rate);
+   return;
+   }
+}
+
 /*
  * Returns:
  * 0: On success. And appropriate error message for duplicate OPPs.
@@ -1646,7 +1674,6 @@ int _opp_add(struct device *dev, struct dev_pm_opp 
*new_opp,
 struct opp_table *opp_table, bool rate_not_available)
 {
struct list_head *head;
-   unsigned int i;
int ret;
 
mutex_lock(_table->lock);
@@ -1672,15 +1699,11 @@ int _opp_add(struct device *dev, struct dev_pm_opp 
*new_opp,
 __func__, new_opp->rate);
}
 
-   for (i = 0; i < opp_table->required_opp_count; i++) {
-   if (new_opp->required_opps[i]->available)
-   continue;
+   /* required-opps not fully initialized yet */
+   if (lazy_linking_pending(opp_table))
+   return 0;
 
-   new_opp->available = false;
-   dev_warn(dev, "%s: OPP not supported by required OPP %pOF 
(%lu)\n",
-__func__, new_opp->required_opps[i]->np, 
new_opp->rate);
-   break;
-   }
+   _required_opps_available(new_opp, opp_table->required_opp_count);
 
return 0;
 }
@@ -2388,6 +2411,10 @@ int dev_pm_opp_xlate_performance_state(struct opp_table 
*src_table,
if (!src_table || !src_table->required_opp_count)
return pstate;
 
+   /* required-opps not fully initialized yet */
+   if (lazy_linking_pending(src_table))
+   return -EBUSY;
+
for (i = 0; i < src_table->required_opp_count; i++) {
if (src_table->required_opp_tables[i]->np == dst_table->np)
break;
diff --git a/drivers/opp/of.c b/drivers/opp/of.c

Re: [PATCH v11 8/9] soc: mediatek: add mtk mutex support for MT8183

2021-01-27 Thread CK Hu
Hi, Hsin-Yi:

On Thu, 2021-01-28 at 15:28 +0800, Hsin-Yi Wang wrote:
> From: Yongqiang Niu 
> 
> Add mtk mutex support for MT8183 SoC.
> 
> Signed-off-by: Yongqiang Niu 
> Signed-off-by: Hsin-Yi Wang 
> ---
>  drivers/soc/mediatek/mtk-mutex.c | 50 
>  1 file changed, 50 insertions(+)
> 
> diff --git a/drivers/soc/mediatek/mtk-mutex.c 
> b/drivers/soc/mediatek/mtk-mutex.c
> index f531b119da7a9..b348f962f82a4 100644
> --- a/drivers/soc/mediatek/mtk-mutex.c
> +++ b/drivers/soc/mediatek/mtk-mutex.c
> @@ -14,6 +14,8 @@
>  
>  #define MT2701_MUTEX0_MOD0   0x2c
>  #define MT2701_MUTEX0_SOF0   0x30
> +#define MT8183_DISP_MUTEX0_MOD0  0x30
> +#define MT8183_DISP_MUTEX0_SOF0  0x2c

Modify 'DISP_MUTEX' to 'MUTEX'

Regards,
CK

>  
>  #define DISP_REG_MUTEX_EN(n) (0x20 + 0x20 * (n))
>  #define DISP_REG_MUTEX(n)(0x24 + 0x20 * (n))
> @@ -37,6 +39,18 @@
>  #define MT8167_MUTEX_MOD_DISP_DITHER 15
>  #define MT8167_MUTEX_MOD_DISP_UFOE   16
>  
> +#define MT8183_MUTEX_MOD_DISP_RDMA0  0
> +#define MT8183_MUTEX_MOD_DISP_RDMA1  1
> +#define MT8183_MUTEX_MOD_DISP_OVL0   9
> +#define MT8183_MUTEX_MOD_DISP_OVL0_2L10
> +#define MT8183_MUTEX_MOD_DISP_OVL1_2L11
> +#define MT8183_MUTEX_MOD_DISP_WDMA0  12
> +#define MT8183_MUTEX_MOD_DISP_COLOR0 13
> +#define MT8183_MUTEX_MOD_DISP_CCORR0 14
> +#define MT8183_MUTEX_MOD_DISP_AAL0   15
> +#define MT8183_MUTEX_MOD_DISP_GAMMA0 16
> +#define MT8183_MUTEX_MOD_DISP_DITHER017
> +
>  #define MT8173_MUTEX_MOD_DISP_OVL0   11
>  #define MT8173_MUTEX_MOD_DISP_OVL1   12
>  #define MT8173_MUTEX_MOD_DISP_RDMA0  13
> @@ -87,6 +101,11 @@
>  #define MT2712_MUTEX_SOF_DSI36
>  #define MT8167_MUTEX_SOF_DPI02
>  #define MT8167_MUTEX_SOF_DPI13
> +#define MT8183_MUTEX_SOF_DSI01
> +#define MT8183_MUTEX_SOF_DPI02
> +
> +#define MT8183_MUTEX_EOF_DSI0(MT8183_MUTEX_SOF_DSI0 
> << 6)
> +#define MT8183_MUTEX_EOF_DPI0(MT8183_MUTEX_SOF_DPI0 
> << 6)
>  
>  struct mtk_mutex {
>   int id;
> @@ -181,6 +200,20 @@ static const unsigned int 
> mt8173_mutex_mod[DDP_COMPONENT_ID_MAX] = {
>   [DDP_COMPONENT_WDMA1] = MT8173_MUTEX_MOD_DISP_WDMA1,
>  };
>  
> +static const unsigned int mt8183_mutex_mod[DDP_COMPONENT_ID_MAX] = {
> + [DDP_COMPONENT_AAL0] = MT8183_MUTEX_MOD_DISP_AAL0,
> + [DDP_COMPONENT_CCORR] = MT8183_MUTEX_MOD_DISP_CCORR0,
> + [DDP_COMPONENT_COLOR0] = MT8183_MUTEX_MOD_DISP_COLOR0,
> + [DDP_COMPONENT_DITHER] = MT8183_MUTEX_MOD_DISP_DITHER0,
> + [DDP_COMPONENT_GAMMA] = MT8183_MUTEX_MOD_DISP_GAMMA0,
> + [DDP_COMPONENT_OVL0] = MT8183_MUTEX_MOD_DISP_OVL0,
> + [DDP_COMPONENT_OVL_2L0] = MT8183_MUTEX_MOD_DISP_OVL0_2L,
> + [DDP_COMPONENT_OVL_2L1] = MT8183_MUTEX_MOD_DISP_OVL1_2L,
> + [DDP_COMPONENT_RDMA0] = MT8183_MUTEX_MOD_DISP_RDMA0,
> + [DDP_COMPONENT_RDMA1] = MT8183_MUTEX_MOD_DISP_RDMA1,
> + [DDP_COMPONENT_WDMA0] = MT8183_MUTEX_MOD_DISP_WDMA0,
> +};
> +
>  static const unsigned int mt2712_mutex_sof[MUTEX_SOF_DSI3 + 1] = {
>   [MUTEX_SOF_SINGLE_MODE] = MUTEX_SOF_SINGLE_MODE,
>   [MUTEX_SOF_DSI0] = MUTEX_SOF_DSI0,
> @@ -198,6 +231,13 @@ static const unsigned int 
> mt8167_mutex_sof[MUTEX_SOF_DSI3 + 1] = {
>   [MUTEX_SOF_DPI1] = MT8167_MUTEX_SOF_DPI1,
>  };
>  
> +/* Add EOF setting so overlay hardware can receive frame done irq */
> +static const unsigned int mt8183_mutex_sof[MUTEX_SOF_DSI3 + 1] = {
> + [MUTEX_SOF_SINGLE_MODE] = MUTEX_SOF_SINGLE_MODE,
> + [MUTEX_SOF_DSI0] = MUTEX_SOF_DSI0 | MT8183_MUTEX_EOF_DSI0,
> + [MUTEX_SOF_DPI0] = MT8183_MUTEX_SOF_DPI0 | MT8183_MUTEX_EOF_DPI0,
> +};
> +
>  static const struct mtk_mutex_data mt2701_mutex_driver_data = {
>   .mutex_mod = mt2701_mutex_mod,
>   .mutex_sof = mt2712_mutex_sof,
> @@ -227,6 +267,14 @@ static const struct mtk_mutex_data 
> mt8173_mutex_driver_data = {
>   .mutex_sof_reg = MT2701_MUTEX0_SOF0,
>  };
>  
> +static const struct mtk_mutex_data mt8183_mutex_driver_data = {
> + .mutex_mod = mt8183_mutex_mod,
> + .mutex_sof = mt8183_mutex_sof,
> + .mutex_mod_reg = MT8183_DISP_MUTEX0_MOD0,
> + .mutex_sof_reg = MT8183_DISP_MUTEX0_SOF0,
> + .no_clk = true,
> +};
> +
>  struct mtk_mutex *mtk_mutex_get(struct device *dev)
>  {
>   struct mtk_mutex_ctx *mtx = dev_get_drvdata(dev);
> @@ -457,6 +505,8 @@ static const struct of_device_id mutex_driver_dt_match[] 
> = {
> .data = _mutex_driver_data},
>   { .compatible = "mediatek,mt8173-disp-mutex",
> .data = _mutex_driver_data},
> + { .compatible = "mediatek,mt8183-disp-mutex",
> +   .data = _mutex_driver_data},
>   {},
>  };
>  

Re: [PATCH] mtd: use refcount to prevent corruption

2021-01-27 Thread Richard Weinberger
Tomas,

- Ursprüngliche Mail -
>> >> Can you please explain a little more what devices are involved?
>> >> Does it implement _get_device() and _put_device()?
>> > No this is not connected to those handlers of the underlying device
>> > and those won't help.
>> > I have a spi device provided by MFD framework so it can go away anytime.
>> 
>> Can it go away physically or just in software?
> Software, but since this is mfd it's basically hotplug. The kernel is crashing
> when I simulate hardware failure.
>> 
>> Usually the pattern is that you make sure in the device driver that nobody 
>> can
>> orphan the MTD while it is in use.
>> e.g. drivers/mtd/ubi/gluebi.c does so. In _get_device() it grabs a reference 
>> on
>> the underlying UBI volume to make sure it cannot go away while the MTD (on
>> top of UBI) is in use.
> 
> I can try that if it helps, because we are simulating possible lower level
> crash.
> In an case I believe that the proper refcouting is much more robust solution,
> than the current one.
> I'd appreciate if someone can review the actual implementation.

This happens right now, I try to understand why exactly the current way is not
good in enough. :-)

Your approach makes sure that the MTD itself does not go away while it has 
users but
how does this help in the case where the underlying MFD just vanishes?
The MTD can be in use and the MFD can go away while e.g. mtd_read() or such
takes place.

Thanks,
//richard


Re: [PATCH 3/3] printk: dump full information of page flags in pGp

2021-01-27 Thread Yafang Shao
On Thu, Jan 28, 2021 at 10:52 AM Miaohe Lin  wrote:
>
> Hi:
> On 2021/1/28 10:19, Yafang Shao wrote:
> > Currently the pGp only shows the names of page flags, rather than
> > the full information including section, node, zone, last cpupid and
> > kasan tag. While it is not easy to parse these information manually
> > because there're so many flavors. Let's interpret them in pGp as well.
> >
> > - Before the patch,
> > [ 6312.639698] ERR: Slab 0x6d1133b9 objects=33 used=3 
> > fp=0x6d0779d1 flags=0x17c0010200(slab|head)
> >
> > - After the patch,
> > [ 6315.235783] ERR: Slab 0x6d1133b9 objects=33 used=3 
> > fp=0x6d0779d1 flags=0x17c0010200(Node 0x0,Zone 0x2,Lastcpupid 
> > 0x1f,slab|head)
> >
>
> Thanks. This really helps!
>
> > Cc: David Hildenbrand 
> > Signed-off-by: Yafang Shao 
> > ---
> >  lib/vsprintf.c | 42 +-
> >  1 file changed, 41 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> > index 3b53c73580c5..bd809f4f1b82 100644
> > --- a/lib/vsprintf.c
> > +++ b/lib/vsprintf.c
> > @@ -1916,6 +1916,46 @@ char *format_flags(char *buf, char *end, unsigned 
> > long flags,
> >   return buf;
> >  }
> >
> > +struct page_flags_layout {
> > + int width;
> > + int shift;
> > + int mask;
> > + char *name;
>
> Should we add const for name ?
>

Good suggestion.

> > +};
> > +
> > +struct page_flags_layout pfl[] = {
>
> Should we add static const for pfl[] as we won't change its value and use it 
> outside this file ?
>

Sure.

> > + {SECTIONS_WIDTH, SECTIONS_PGSHIFT, SECTIONS_MASK, "Section "},
> > + {NODES_WIDTH, NODES_PGSHIFT, NODES_MASK, "Node "},
> > + {ZONES_WIDTH, ZONES_PGSHIFT, ZONES_MASK, "Zone "},
> > + {LAST_CPUPID_WIDTH, LAST_CPUPID_PGSHIFT, LAST_CPUPID_MASK, 
> > "Lastcpupid "},
> > + {KASAN_TAG_WIDTH, KASAN_TAG_PGSHIFT, KASAN_TAG_MASK, "Kasantag "},
> > +};
> > +
> > +static
> > +char *format_layout(char *buf, char *end, unsigned long flags)
> > +{
> > + int i;
> > +
> > + for (i = 0; i < sizeof(pfl) / sizeof(struct page_flags_layout) && buf 
> > < end; i++) {
>
> I think we can use ARRAY_SIZE here.
>

Sure.

> > + if (pfl[i].width == 0)
> > + continue;
> > +
> > + buf = string(buf, end, pfl[i].name, default_str_spec);
> > +
> > + if (buf >= end)
> > + break;
> > + buf = number(buf, end, (flags >> pfl[i].shift) & pfl[i].mask,
> > +  default_flag_spec);
> > +
> > + if (buf >= end)
> > + break;
> > + *buf = ',';
> > + buf++;
> > + }
> > +
> > + return buf;
> > +}
> > +
> >  static noinline_for_stack
> >  char *flags_string(char *buf, char *end, void *flags_ptr,
> >  struct printf_spec spec, const char *fmt)
> > @@ -1929,7 +1969,7 @@ char *flags_string(char *buf, char *end, void 
> > *flags_ptr,
> >   switch (fmt[1]) {
> >   case 'p':
> >   flags = *(unsigned long *)flags_ptr;
> > - /* Remove zone id */
> > + buf = format_layout(buf, end, flags & ~((1UL << NR_PAGEFLAGS) 
> > - 1));
> >   flags &= (1UL << NR_PAGEFLAGS) - 1;
> >   names = pageflag_names;
> >   break;
> >
> Many thanks.



-- 
Thanks
Yafang


Re: [PATCH v11 7/9] drm/mediatek: enable dither function

2021-01-27 Thread CK Hu
Hi, Hsin-Yi:

On Thu, 2021-01-28 at 15:28 +0800, Hsin-Yi Wang wrote:
> From: Yongqiang Niu 
> 
> for 5 or 6 bpc panel, we need enable dither function
> to improve the display quality
> 
> Signed-off-by: Yongqiang Niu 
> Signed-off-by: Hsin-Yi Wang 
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 44 -
>  1 file changed, 43 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c 
> b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> index 8173f709272be..e85625704d611 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> @@ -53,7 +53,9 @@
>  #define DITHER_ENBIT(0)
>  #define DISP_DITHER_CFG  0x0020
>  #define DITHER_RELAY_MODEBIT(0)
> +#define DITHER_ENGINE_EN BIT(1)
>  #define DISP_DITHER_SIZE 0x0030
> +#define DITHER_REG(idx)  (0x100 + (idx) * 4)
>  
>  #define LUT_10BIT_MASK   0x03ff
>  
> @@ -313,8 +315,48 @@ static void mtk_dither_config(struct device *dev, 
> unsigned int w,
>  {
>   struct mtk_ddp_comp_dev *priv = dev_get_drvdata(dev);
>  
> + bool enable = false;
> +
> + /* default value for dither reg 5 to 14 */
> + const u32 dither_setting[] = {
> + 0x, /* 5 */
> + 0x3002, /* 6 */
> + 0x, /* 7 */
> + 0x, /* 8 */
> + 0x, /* 9 */
> + 0x, /* 10 */
> + 0x, /* 11 */
> + 0x0011, /* 12 */
> + 0x, /* 13 */
> + 0x, /* 14 */

Could you explain what is this?

> + };
> +
> + if (bpc == 5 || bpc == 6) {
> + enable = true;
> + mtk_ddp_write(cmdq_pkt,
> +   DITHER_LSB_ERR_SHIFT_R(MTK_MAX_BPC - bpc) |
> +   DITHER_ADD_LSHIFT_R(MTK_MAX_BPC - bpc) |
> +   DITHER_NEW_BIT_MODE,
> +   >cmdq_reg, priv->regs, DITHER_REG(15));
> + mtk_ddp_write(cmdq_pkt,
> +   DITHER_LSB_ERR_SHIFT_B(MTK_MAX_BPC - bpc) |
> +   DITHER_ADD_LSHIFT_B(MTK_MAX_BPC - bpc) |
> +   DITHER_LSB_ERR_SHIFT_G(MTK_MAX_BPC - bpc) |
> +   DITHER_ADD_LSHIFT_G(MTK_MAX_BPC - bpc),

This result in 0x50505050, but previous version is 0x50504040, so this
version is correct and previous version is incorrect?

Regards,
CK

> +   >cmdq_reg, priv->regs, DITHER_REG(16));
> + }
> +
> +
> + if (enable) {
> + u32 idx;
> +
> + for (idx = 0; idx < ARRAY_SIZE(dither_setting); idx++)
> + mtk_ddp_write(cmdq_pkt, dither_setting[idx], 
> >cmdq_reg, priv->regs,
> +   DITHER_REG(idx + 5));
> + }
> +
>   mtk_ddp_write(cmdq_pkt, h << 16 | w, >cmdq_reg, priv->regs, 
> DISP_DITHER_SIZE);
> - mtk_ddp_write(cmdq_pkt, DITHER_RELAY_MODE, >cmdq_reg, priv->regs, 
> DISP_DITHER_CFG);
> +mtk_ddp_write(cmdq_pkt, enable ? DITHER_ENGINE_EN : 
> DITHER_RELAY_MODE, >cmdq_reg, priv->regs, DISP_DITHER_CFG);
>  }
>  
>  static void mtk_dither_start(struct device *dev)



[RFC PATCH 11/34] nvmet: use bio_new in nvmet_bdev_execute_rw

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/nvme/target/io-cmd-bdev.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/nvme/target/io-cmd-bdev.c 
b/drivers/nvme/target/io-cmd-bdev.c
index bf6e0ac9ad28..f5fd93a796a6 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -225,6 +225,7 @@ static int nvmet_bdev_alloc_bip(struct nvmet_req *req, 
struct bio *bio,
 
 static void nvmet_bdev_execute_rw(struct nvmet_req *req)
 {
+   struct block_device *bdev = req->ns->bdev;
int sg_cnt = req->sg_cnt;
struct bio *bio;
struct scatterlist *sg;
@@ -265,7 +266,7 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req)
} else {
bio = bio_alloc(GFP_KERNEL, min(sg_cnt, BIO_MAX_PAGES));
}
-   bio_set_dev(bio, req->ns->bdev);
+   bio_set_dev(bio, bdev);
bio->bi_iter.bi_sector = sector;
bio->bi_private = req;
bio->bi_end_io = nvmet_bio_done;
@@ -290,11 +291,7 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req)
}
}
 
-   bio = bio_alloc(GFP_KERNEL, min(sg_cnt, BIO_MAX_PAGES));
-   bio_set_dev(bio, req->ns->bdev);
-   bio->bi_iter.bi_sector = sector;
-   bio->bi_opf = op;
-
+   bio = bio_new(bdev, sector, op, 0, sg_cnt, GFP_KERNEL);
bio_chain(bio, prev);
submit_bio(prev);
}
-- 
2.22.1



[RFC PATCH 10/34] dm-zoned: use bio_new in dmz_rdwr_block

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/md/dm-zoned-metadata.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
index fa0ee732c6e9..5b5ed5fce2ed 100644
--- a/drivers/md/dm-zoned-metadata.c
+++ b/drivers/md/dm-zoned-metadata.c
@@ -755,13 +755,11 @@ static int dmz_rdwr_block(struct dmz_dev *dev, int op,
if (dmz_bdev_is_dying(dev))
return -EIO;
 
-   bio = bio_alloc(GFP_NOIO, 1);
+   bio = bio_new(dev->bdev, dmz_blk2sect(block), op,
+ REQ_SYNC | REQ_META | REQ_PRIO, 1, GFP_NOIO);
if (!bio)
return -ENOMEM;
 
-   bio->bi_iter.bi_sector = dmz_blk2sect(block);
-   bio_set_dev(bio, dev->bdev);
-   bio_set_op_attrs(bio, op, REQ_SYNC | REQ_META | REQ_PRIO);
bio_add_page(bio, page, DMZ_BLOCK_SIZE, 0);
ret = submit_bio_wait(bio);
bio_put(bio);
-- 
2.22.1



[RFC PATCH 14/34] fs/buffer: use bio_new in submit_bh_wbc

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/buffer.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 32647d2011df..fcbea667fa04 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -3023,12 +3023,16 @@ static int submit_bh_wbc(int op, int op_flags, struct 
buffer_head *bh,
if (test_set_buffer_req(bh) && (op == REQ_OP_WRITE))
clear_buffer_write_io_error(bh);
 
-   bio = bio_alloc(GFP_NOIO, 1);
+   if (buffer_meta(bh))
+   op_flags |= REQ_META;
+   if (buffer_prio(bh))
+   op_flags |= REQ_PRIO;
+
+   bio = bio_new(bh->b_bdev,  bh->b_blocknr * (bh->b_size >> 9), op,
+ op_flags, GFP_NOIO, 1);
 
fscrypt_set_bio_crypt_ctx_bh(bio, bh, GFP_NOIO);
 
-   bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);
-   bio_set_dev(bio, bh->b_bdev);
bio->bi_write_hint = write_hint;
 
bio_add_page(bio, bh->b_page, bh->b_size, bh_offset(bh));
@@ -3037,12 +3041,6 @@ static int submit_bh_wbc(int op, int op_flags, struct 
buffer_head *bh,
bio->bi_end_io = end_bio_bh_io_sync;
bio->bi_private = bh;
 
-   if (buffer_meta(bh))
-   op_flags |= REQ_META;
-   if (buffer_prio(bh))
-   op_flags |= REQ_PRIO;
-   bio_set_op_attrs(bio, op, op_flags);
-
/* Take care of bh's that straddle the end of the device */
guard_bio_eod(bio);
 
-- 
2.22.1



[PATCH v2 2/3] isofs: handle large user and group ID

2021-01-27 Thread bingjingc
From: BingJing Chang 

If uid or gid of mount options is larger than INT_MAX, isofs_fill_super
will return -EINVAL.

The problem can be encountered by a domain user or reproduced via:
mount -o loop,uid=2147483648 ubuntu-16.04.6-server-amd64.iso /mnt

This can be fixed as commit 233a01fa9c4c ("fuse: handle large user and
group ID").

Reviewed-by: Robbie Ko 
Reviewed-by: Chung-Chiang Cheng 
Reviewed-by: Matthew Wilcox 
Signed-off-by: BingJing Chang 
---
 fs/isofs/inode.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
index ec90773..21edc42 100644
--- a/fs/isofs/inode.c
+++ b/fs/isofs/inode.c
@@ -339,6 +339,7 @@ static int parse_options(char *options, struct 
iso9660_options *popt)
 {
char *p;
int option;
+   unsigned int uv;
 
popt->map = 'n';
popt->rock = 1;
@@ -434,17 +435,17 @@ static int parse_options(char *options, struct 
iso9660_options *popt)
case Opt_ignore:
break;
case Opt_uid:
-   if (match_int([0], ))
+   if (match_uint([0], ))
return 0;
-   popt->uid = make_kuid(current_user_ns(), option);
+   popt->uid = make_kuid(current_user_ns(), uv);
if (!uid_valid(popt->uid))
return 0;
popt->uid_set = 1;
break;
case Opt_gid:
-   if (match_int([0], ))
+   if (match_uint([0], ))
return 0;
-   popt->gid = make_kgid(current_user_ns(), option);
+   popt->gid = make_kgid(current_user_ns(), uv);
if (!gid_valid(popt->gid))
return 0;
popt->gid_set = 1;
-- 
2.7.4



[PATCH v2 1/3] parser: add unsigned int parser

2021-01-27 Thread bingjingc
From: BingJing Chang 

Will be used by fs parsing options & fix kernel-doc typos

Reviewed-by: Robbie Ko
Reviewed-by: Chung-Chiang Cheng 
Reviewed-by: Matthew Wilcox 
Reviewed-by: Randy Dunlap 
Signed-off-by: BingJing Chang 
---
 include/linux/parser.h |  1 +
 lib/parser.c   | 44 +---
 2 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/include/linux/parser.h b/include/linux/parser.h
index 89e2b23..dd79f45 100644
--- a/include/linux/parser.h
+++ b/include/linux/parser.h
@@ -29,6 +29,7 @@ typedef struct {
 
 int match_token(char *, const match_table_t table, substring_t args[]);
 int match_int(substring_t *, int *result);
+int match_uint(substring_t *s, unsigned int *result);
 int match_u64(substring_t *, u64 *result);
 int match_octal(substring_t *, int *result);
 int match_hex(substring_t *, int *result);
diff --git a/lib/parser.c b/lib/parser.c
index f5b3e5d..f2b9a8e 100644
--- a/lib/parser.c
+++ b/lib/parser.c
@@ -11,7 +11,7 @@
 #include 
 
 /**
- * match_one: - Determines if a string matches a simple pattern
+ * match_one - Determines if a string matches a simple pattern
  * @s: the string to examine for presence of the pattern
  * @p: the string containing the pattern
  * @args: array of %MAX_OPT_ARGS _t elements. Used to return match
@@ -89,7 +89,7 @@ static int match_one(char *s, const char *p, substring_t 
args[])
 }
 
 /**
- * match_token: - Find a token (and optional args) in a string
+ * match_token - Find a token (and optional args) in a string
  * @s: the string to examine for token/argument pairs
  * @table: match_table_t describing the set of allowed option tokens and the
  * arguments that may be associated with them. Must be terminated with a
@@ -114,7 +114,7 @@ int match_token(char *s, const match_table_t table, 
substring_t args[])
 EXPORT_SYMBOL(match_token);
 
 /**
- * match_number: scan a number in the given base from a substring_t
+ * match_number - scan a number in the given base from a substring_t
  * @s: substring to be scanned
  * @result: resulting integer on success
  * @base: base to use when converting string
@@ -147,7 +147,7 @@ static int match_number(substring_t *s, int *result, int 
base)
 }
 
 /**
- * match_u64int: scan a number in the given base from a substring_t
+ * match_u64int - scan a number in the given base from a substring_t
  * @s: substring to be scanned
  * @result: resulting u64 on success
  * @base: base to use when converting string
@@ -174,7 +174,7 @@ static int match_u64int(substring_t *s, u64 *result, int 
base)
 }
 
 /**
- * match_int: - scan a decimal representation of an integer from a substring_t
+ * match_int - scan a decimal representation of an integer from a substring_t
  * @s: substring_t to be scanned
  * @result: resulting integer on success
  *
@@ -188,8 +188,30 @@ int match_int(substring_t *s, int *result)
 }
 EXPORT_SYMBOL(match_int);
 
+/*
+ * match_uint - scan a decimal representation of an integer from a substring_t
+ * @s: substring_t to be scanned
+ * @result: resulting integer on success
+ *
+ * Description: Attempts to parse the _t @s as a decimal integer. On
+ * success, sets @result to the integer represented by the string and returns 
0.
+ * Returns -ENOMEM, -EINVAL, or -ERANGE on failure.
+ */
+int match_uint(substring_t *s, unsigned int *result)
+{
+   int err = -ENOMEM;
+   char *buf = match_strdup(s);
+
+   if (buf) {
+   err = kstrtouint(buf, 10, result);
+   kfree(buf);
+   }
+   return err;
+}
+EXPORT_SYMBOL(match_uint);
+
 /**
- * match_u64: - scan a decimal representation of a u64 from
+ * match_u64 - scan a decimal representation of a u64 from
  *  a substring_t
  * @s: substring_t to be scanned
  * @result: resulting unsigned long long on success
@@ -206,7 +228,7 @@ int match_u64(substring_t *s, u64 *result)
 EXPORT_SYMBOL(match_u64);
 
 /**
- * match_octal: - scan an octal representation of an integer from a substring_t
+ * match_octal - scan an octal representation of an integer from a substring_t
  * @s: substring_t to be scanned
  * @result: resulting integer on success
  *
@@ -221,7 +243,7 @@ int match_octal(substring_t *s, int *result)
 EXPORT_SYMBOL(match_octal);
 
 /**
- * match_hex: - scan a hex representation of an integer from a substring_t
+ * match_hex - scan a hex representation of an integer from a substring_t
  * @s: substring_t to be scanned
  * @result: resulting integer on success
  *
@@ -236,7 +258,7 @@ int match_hex(substring_t *s, int *result)
 EXPORT_SYMBOL(match_hex);
 
 /**
- * match_wildcard: - parse if a string matches given wildcard pattern
+ * match_wildcard - parse if a string matches given wildcard pattern
  * @pattern: wildcard pattern
  * @str: the string to be parsed
  *
@@ -287,7 +309,7 @@ bool match_wildcard(const char *pattern, const char *str)
 EXPORT_SYMBOL(match_wildcard);
 
 /**
- * match_strlcpy: - Copy the characters from a substring_t to a sized buffer
+ * 

[RFC PATCH 07/34] dm: use bio_new in dm-log-writes

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/md/dm-log-writes.c | 30 ++
 1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/drivers/md/dm-log-writes.c b/drivers/md/dm-log-writes.c
index e3d35c6c9f71..7ca9af407647 100644
--- a/drivers/md/dm-log-writes.c
+++ b/drivers/md/dm-log-writes.c
@@ -217,18 +217,15 @@ static int write_metadata(struct log_writes_c *lc, void 
*entry,
void *ptr;
size_t ret;
 
-   bio = bio_alloc(GFP_KERNEL, 1);
+   bio = bio_new(lc->logdev->bdev, sector, REQ_OP_WRITE, 0, 1, GFP_KERNEL);
if (!bio) {
DMERR("Couldn't alloc log bio");
goto error;
}
bio->bi_iter.bi_size = 0;
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, lc->logdev->bdev);
bio->bi_end_io = (sector == WRITE_LOG_SUPER_SECTOR) ?
  log_end_super : log_end_io;
bio->bi_private = lc;
-   bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
 
page = alloc_page(GFP_KERNEL);
if (!page) {
@@ -264,7 +261,7 @@ static int write_inline_data(struct log_writes_c *lc, void 
*entry,
 size_t entrylen, void *data, size_t datalen,
 sector_t sector)
 {
-   int num_pages, bio_pages, pg_datalen, pg_sectorlen, i;
+   int num_pages, pg_datalen, pg_sectorlen, i;
struct page *page;
struct bio *bio;
size_t ret;
@@ -272,24 +269,21 @@ static int write_inline_data(struct log_writes_c *lc, 
void *entry,
 
while (datalen) {
num_pages = ALIGN(datalen, PAGE_SIZE) >> PAGE_SHIFT;
-   bio_pages = min(num_pages, BIO_MAX_PAGES);
 
atomic_inc(>io_blocks);
 
-   bio = bio_alloc(GFP_KERNEL, bio_pages);
+   bio = bio_new(lc->logdev->bdev, sector, REQ_OP_WRITE, 0,
+ num_pages, GFP_KERNEL);
if (!bio) {
DMERR("Couldn't alloc inline data bio");
goto error;
}
 
bio->bi_iter.bi_size = 0;
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, lc->logdev->bdev);
bio->bi_end_io = log_end_io;
bio->bi_private = lc;
-   bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
 
-   for (i = 0; i < bio_pages; i++) {
+   for (i = 0; i < bio->bi_max_vecs; i++) {
pg_datalen = min_t(int, datalen, PAGE_SIZE);
pg_sectorlen = ALIGN(pg_datalen, lc->sectorsize);
 
@@ -317,7 +311,7 @@ static int write_inline_data(struct log_writes_c *lc, void 
*entry,
}
submit_bio(bio);
 
-   sector += bio_pages * PAGE_SECTORS;
+   sector += bio->bi_max_vecs * PAGE_SECTORS;
}
return 0;
 error_bio:
@@ -364,17 +358,15 @@ static int log_one_block(struct log_writes_c *lc,
goto out;
 
atomic_inc(>io_blocks);
-   bio = bio_alloc(GFP_KERNEL, min(block->vec_cnt, BIO_MAX_PAGES));
+   bio = bio_new(lc->logdev->bdev, sector, REQ_OP_WRITE, 0,
+   block->vec_cnt, GFP_KERNEL);
if (!bio) {
DMERR("Couldn't alloc log bio");
goto error;
}
bio->bi_iter.bi_size = 0;
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, lc->logdev->bdev);
bio->bi_end_io = log_end_io;
bio->bi_private = lc;
-   bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
 
for (i = 0; i < block->vec_cnt; i++) {
/*
@@ -386,17 +378,15 @@ static int log_one_block(struct log_writes_c *lc,
if (ret != block->vecs[i].bv_len) {
atomic_inc(>io_blocks);
submit_bio(bio);
-   bio = bio_alloc(GFP_KERNEL, min(block->vec_cnt - i, 
BIO_MAX_PAGES));
+   bio = bio_new(lc->logdev->bdev, sector, REQ_OP_WRITE,
+   0, block->vec_cnt - i, GFP_KERNEL);
if (!bio) {
DMERR("Couldn't alloc log bio");
goto error;
}
bio->bi_iter.bi_size = 0;
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, lc->logdev->bdev);
bio->bi_end_io = log_end_io;
bio->bi_private = lc;
-   bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
 
ret = bio_add_page(bio, block->vecs[i].bv_page,
   block->vecs[i].bv_len, 0);
-- 
2.22.1



[PATCH v2 3/3] udf: handle large user and group ID

2021-01-27 Thread bingjingc
From: BingJing Chang 

If uid or gid of mount options is larger than INT_MAX, udf_fill_super will
return -EINVAL.

The problem can be encountered by a domain user or reproduced via:
mount -o loop,uid=2147483648 something-in-udf-format.iso /mnt

This can be fixed as commit 233a01fa9c4c ("fuse: handle large user and
group ID").

Reviewed-by: Robbie Ko 
Reviewed-by: Chung-Chiang Cheng 
Reviewed-by: Matthew Wilcox 
Signed-off-by: BingJing Chang 
---
 fs/udf/super.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/udf/super.c b/fs/udf/super.c
index d0df217..2f83c12 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -459,6 +459,7 @@ static int udf_parse_options(char *options, struct 
udf_options *uopt,
 {
char *p;
int option;
+   unsigned int uv;
 
uopt->novrs = 0;
uopt->session = 0x;
@@ -508,17 +509,17 @@ static int udf_parse_options(char *options, struct 
udf_options *uopt,
uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD);
break;
case Opt_gid:
-   if (match_int(args, ))
+   if (match_uint(args, ))
return 0;
-   uopt->gid = make_kgid(current_user_ns(), option);
+   uopt->gid = make_kgid(current_user_ns(), uv);
if (!gid_valid(uopt->gid))
return 0;
uopt->flags |= (1 << UDF_FLAG_GID_SET);
break;
case Opt_uid:
-   if (match_int(args, ))
+   if (match_uint(args, ))
return 0;
-   uopt->uid = make_kuid(current_user_ns(), option);
+   uopt->uid = make_kuid(current_user_ns(), uv);
if (!uid_valid(uopt->uid))
return 0;
uopt->flags |= (1 << UDF_FLAG_UID_SET);
-- 
2.7.4



Re: [PATCH 3/3] printk: dump full information of page flags in pGp

2021-01-27 Thread Yafang Shao
On Thu, Jan 28, 2021 at 10:35 AM Joe Perches  wrote:
>
> On Thu, 2021-01-28 at 10:19 +0800, Yafang Shao wrote:
> > Currently the pGp only shows the names of page flags, rather than
> > the full information including section, node, zone, last cpupid and
> > kasan tag. While it is not easy to parse these information manually
> > because there're so many flavors. Let's interpret them in pGp as well.
> []
> > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> []
> > @@ -1916,6 +1916,46 @@ char *format_flags(char *buf, char *end, unsigned 
> > long flags,
> >   return buf;
> >  }
> >
> > +struct page_flags_layout {
> > + int width;
> > + int shift;
> > + int mask;
> > + char *name;
> > +};
> > +
> > +struct page_flags_layout pfl[] = {
>
> static const struct page_flags_layout pfl[] = {

Sure.

>
> > + {SECTIONS_WIDTH, SECTIONS_PGSHIFT, SECTIONS_MASK, "Section "},
> > + {NODES_WIDTH, NODES_PGSHIFT, NODES_MASK, "Node "},
> > + {ZONES_WIDTH, ZONES_PGSHIFT, ZONES_MASK, "Zone "},
> > + {LAST_CPUPID_WIDTH, LAST_CPUPID_PGSHIFT, LAST_CPUPID_MASK, 
> > "Lastcpupid "},
> > + {KASAN_TAG_WIDTH, KASAN_TAG_PGSHIFT, KASAN_TAG_MASK, "Kasantag "},
> > +};
> > +
> > +static
> > +char *format_layout(char *buf, char *end, unsigned long flags)
>
> poor name.  perhaps format_page_flags
>

Thanks for the suggestion.

> > +{
> > + int i;
> > +
> > + for (i = 0; i < sizeof(pfl) / sizeof(struct page_flags_layout) && buf 
> > < end; i++) {
>
> for (i = 0; i < ARRAY_SIZE(pfl) && buf < end; i++) {
>

Sure.


>
> > @@ -1929,7 +1969,7 @@ char *flags_string(char *buf, char *end, void 
> > *flags_ptr,
> >   switch (fmt[1]) {
> >   case 'p':
> >   flags = *(unsigned long *)flags_ptr;
> > - /* Remove zone id */
> > + buf = format_layout(buf, end, flags & ~((1UL << NR_PAGEFLAGS) 
> > - 1));
> >   flags &= (1UL << NR_PAGEFLAGS) - 1;
>
> Perhaps store the bitshift into a temp and use the temp twice
>
> foo = BIT(NR_PAGEFLAGS) - 1;
>
> buf = format_layout(buf, end, flags & ~foo);
> flags &= foo;
>
>

Thanks for the suggestion. I will change them all.


-- 
Thanks
Yafang


Re: [PATCH 0/4] add xhci hooks for USB offload

2021-01-27 Thread Greg KH
On Thu, Jan 28, 2021 at 08:31:14AM +0200, Mathias Nyman wrote:
> On 28.1.2021 5.38, Howard Yen wrote:
> > On Tue, Jan 26, 2021 at 10:19 PM Greg KH  wrote:
> >>
> >> On Fri, Jan 22, 2021 at 05:32:58PM +0200, Mathias Nyman wrote:
> >>>
> >>> Ok, before adding hooks like this I think we need to see how they are 
> >>> used.
> >>> Do you have the rest of the patches that go on top of this series?
> >>>
> >>> Maybe it could make sense to use overrides for the functions in struct 
> >>> hc_driver
> >>> instead in some cases? There is support for that already.
> >>
> >> What overrides could be done for these changes?  At first glance that
> >> would seem to require a lot of duplicated code in whatever override
> >> happens to be needed.
> >>
> >> thanks,
> >>
> >> greg k-h
> > 
> > This patch series is all the changes for the offload hooks currently.
> > 
> > I thought about this, but if I tried to override the functions in
> > struct hc_driver, that'll need to
> > copy many code to the override function, and it won't follow the
> > latest change in the core
> > xhci driver.
> > 
> > 
> > - Howard
> 
> Ok, I see. 
> 
> The point I'm trying to make is that there is no way for me to know if
> these hooks are the right solution before I see any code using them.
> 
> Is the offloading code ready and public somewhere?

There is offload code published in the last few Samsung phone kernels, I
want to get that ported to these hooks to see if that works properly.

Give me a few days and I'll see if I can get it working, I had a
half-finished port around here somewhere...

thanks,

greg k-h


Re: [RESEND PATCH 1/2] KVM: X86: Add support for the emulation of DR6_BUS_LOCK bit

2021-01-27 Thread Xiaoyao Li

On 1/28/2021 3:25 PM, Paolo Bonzini wrote:

On 28/01/21 08:17, Xiaoyao Li wrote:


"Active low" means that the bit is usually 1 and goes to 0 when the 
condition (such as RTM or bus lock) happens.  For almost all those 
DR6 bits the value is in fact always 1, but if they are defined in 
the future it will require no code change.


Why not keep use DR6_INIT, or DR6_RESET_VALUE? or any other better name.

It's just the default clear value of DR6 that no debug condition is hit.


I preferred "DR6_ACTIVE_LOW" because the value is used only once or 
twice to initialize dr6, and many times to invert those bits.  For example:


vcpu->arch.dr6 &= ~DR_TRAP_BITS;
vcpu->arch.dr6 |= DR6_ACTIVE_LOW;
vcpu->arch.dr6 |= payload;
vcpu->arch.dr6 ^= payload & DR6_ACTIVE_LOW;

payload = vcpu->arch.dr6;
payload &= ~DR6_BT;
payload ^= DR6_ACTIVE_LOW;

The name conveys that it's not just the initialization value; it's also 
the XOR mask between the #DB exit qualification (which we also use as 
the "payload") and DR6.


Fair enough.



Re: [PATCH 1/2] qspinlock: Ensure writes are pushed out of core write buffer

2021-01-27 Thread Alexander Sverdlin
Hi!

On 27/01/2021 23:43, Peter Zijlstra wrote:
> On Wed, Jan 27, 2021 at 09:01:08PM +0100, Alexander A Sverdlin wrote:
>> From: Alexander Sverdlin 
>>
>> Ensure writes are pushed out of core write buffer to prevent waiting code
>> on another cores from spinning longer than necessary.
> Our smp_wmb() as defined does not have that property. You're relying on
> some arch specific details which do not belong in common code.

Yes, my intention was SYNCW on Octeon, which by accident is smp_wmb().
Do you think that the core write buffer is only Octeon feature and there
will be no others?

Should I re-implement arch_mcs_spin_lock_contended() for Octeon only,
as it has been done for ARM?

>> diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
>> index 5e10153..10e497a 100644
>> --- a/kernel/locking/mcs_spinlock.h
>> +++ b/kernel/locking/mcs_spinlock.h
>> @@ -89,6 +89,11 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct 
>> mcs_spinlock *node)
>>  return;
>>  }
>>  WRITE_ONCE(prev->next, node);
>> +/*
>> + * This is necessary to make sure that the corresponding "while" in the
>> + * mcs_spin_unlock() doesn't loop forever
>> + */
> This comment is utterly inadequate, since it does not describe an
> explicit ordering between two (or more) stores.
> 
>> +smp_wmb();
>>  
>>  /* Wait until the lock holder passes the lock down. */
>>  arch_mcs_spin_lock_contended(>locked);
>> diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c
>> index cbff6ba..577fe01 100644
>> --- a/kernel/locking/qspinlock.c
>> +++ b/kernel/locking/qspinlock.c
>> @@ -469,6 +469,12 @@ void queued_spin_lock_slowpath(struct qspinlock *lock, 
>> u32 val)
>>  
>>  /* Link @node into the waitqueue. */
>>  WRITE_ONCE(prev->next, node);
>> +/*
>> + * This is necessary to make sure that the corresponding
>> + * smp_cond_load_relaxed() below (running on another core)
>> + * doesn't spin forever.
>> + */
>> +smp_wmb();
> That's insane, cache coherency should not allow that to happen in the
> first place. Our smp_wmb() cannot help with that.
> 

-- 
Best regards,
Alexander Sverdlin.


Re: [RFC 1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory

2021-01-27 Thread Anshuman Khandual


On 1/27/21 2:59 PM, David Hildenbrand wrote:
> On 27.01.21 05:06, Anshuman Khandual wrote:
>>
>>
>> On 1/25/21 2:43 PM, David Hildenbrand wrote:
>>> On 25.01.21 07:22, Anshuman Khandual wrote:

 On 12/22/20 12:42 PM, Anshuman Khandual wrote:
> pfn_valid() asserts that there is a memblock entry for a given pfn without
> MEMBLOCK_NOMAP flag being set. The problem with ZONE_DEVICE based memory 
> is
> that they do not have memblock entries. Hence memblock_is_map_memory() 
> will
> invariably fail via memblock_search() for a ZONE_DEVICE based address. 
> This
> eventually fails pfn_valid() which is wrong. memblock_is_map_memory() 
> needs
> to be skipped for such memory ranges. As ZONE_DEVICE memory gets 
> hotplugged
> into the system via memremap_pages() called from a driver, their 
> respective
> memory sections will not have SECTION_IS_EARLY set.
>
> Normal hotplug memory will never have MEMBLOCK_NOMAP set in their memblock
> regions. Because the flag MEMBLOCK_NOMAP was specifically designed and set
> for firmware reserved memory regions. memblock_is_map_memory() can just be
> skipped as its always going to be positive and that will be an 
> optimization
> for the normal hotplug memory. Like ZONE_DEVIE based memory, all 
> hotplugged
> normal memory too will not have SECTION_IS_EARLY set for their sections.
>
> Skipping memblock_is_map_memory() for all non early memory sections would
> fix pfn_valid() problem for ZONE_DEVICE based memory and also improve its
> performance for normal hotplug memory as well.
>
> Cc: Catalin Marinas 
> Cc: Will Deacon 
> Cc: Ard Biesheuvel 
> Cc: Robin Murphy 
> Cc: linux-arm-ker...@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> Fixes: 73b20c84d42d ("arm64: mm: implement pte_devmap support")
> Signed-off-by: Anshuman Khandual 

 Hello David/Mike,

 Given that we would need to rework early sections, memblock semantics via a
 new config i.e EARLY_SECTION_MEMMAP_HOLES and also some possible changes to
 ARCH_KEEP_MEMBLOCK and HAVE_ARCH_PFN_VALID, wondering if these patches here
 which fixes a problem (and improves performance) can be merged first. After
 that, I could start working on the proposed rework. Could you please let me
 know your thoughts on this. Thank you.
>>>
>>> As I said, we might have to throw in an pfn_section_valid() check, to
>>> catch not-section-aligned ZONE_DEVICE ranges (I assume this is possible
>>> on arm64 as well, no?).
>>
>> pfn_section_valid() should be called only for !early_section() i.e normal
>> hotplug and ZONE_DEVICE memory ? Because early boot memory should always
>> be section aligned.
> 
> Well, at least not on x86-64 you can have early sections intersect with 
> ZONE_DEVICE memory.
> 
> E.g., have 64MB boot memory in a section. Later, we add ZONE_DEVICE memory 
> which might cover the remaining 64MB. For pfn_valid() on x86-64, we always 
> return "true" for such sections, because we always have the memmap for the 
> whole early section allocated during boot. So, there it's "simple".

This is the generic pfn_valid() used on X86. As you mentioned this
does not test pfn_section_valid() if the section is early assuming
that vmemmap coverage is complete.

#ifndef CONFIG_HAVE_ARCH_PFN_VALID
static inline int pfn_valid(unsigned long pfn)
{
struct mem_section *ms;

if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
return 0;
ms = __nr_to_section(pfn_to_section_nr(pfn));
if (!valid_section(ms))
return 0;
/*
 * Traditionally early sections always returned pfn_valid() for
 * the entire section-sized span.
 */
return early_section(ms) || pfn_section_valid(ms, pfn);
}
#endif

Looking at the code, seems like early sections get initialized via
sparse_init() only in section granularity but then please correct
me otherwise.

> 
> Now, arm64 seems to discard some parts of the vmemmap, so the remaining 64MB 
> in such an early section might not have a memmap anymore? TBH, I don't know.

Did not get that. Could you please be more specific on how arm64 discards
parts of the vmemmap.

> 
> Most probably only performing the check for
> !early_section() is sufficient on arm64, but I really can't tell as I don't 
> know what we're actually discarding and if something as described for x86-64 
> is even possible on arm64.

Seems like direct users for arch_add_memory() and __add_pages() like
pagemap_range() can cause subsection hotplug and vmemmap mapping. So
pfn_section_valid() should be applicable only for !early_sections().

Although a simple test on arm64 shows that both boot memory and
traditional memory hotplug gets entire subsection_map populated. But
that might not be always true for ZONE_DEVICE memory.

> 
> We should really try to take the magic out of arm64 

Re: [PATCH] KVM: x86: fix CPUID entries returned by KVM_GET_CPUID2 ioctl

2021-01-27 Thread Paolo Bonzini

On 28/01/21 03:44, Michael Roth wrote:

Recent commit 255cbecfe0 modified struct kvm_vcpu_arch to make
'cpuid_entries' a pointer to an array of kvm_cpuid_entry2 entries
rather than embedding the array in the struct. KVM_SET_CPUID and
KVM_SET_CPUID2 were updated accordingly, but KVM_GET_CPUID2 was missed.

As a result, KVM_GET_CPUID2 currently returns random fields from struct
kvm_vcpu_arch to userspace rather than the expected CPUID values. Fix
this by treating 'cpuid_entries' as a pointer when copying its
contents to userspace buffer.

Fixes: 255cbecfe0c9 ("KVM: x86: allocate vcpu->arch.cpuid_entries dynamically")
Cc: Vitaly Kuznetsov 
Signed-off-by: Michael Roth 
---
  arch/x86/kvm/cpuid.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 13036cf0b912..38172ca627d3 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -321,7 +321,7 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
if (cpuid->nent < vcpu->arch.cpuid_nent)
goto out;
r = -EFAULT;
-   if (copy_to_user(entries, >arch.cpuid_entries,
+   if (copy_to_user(entries, vcpu->arch.cpuid_entries,
 vcpu->arch.cpuid_nent * sizeof(struct 
kvm_cpuid_entry2)))
goto out;
return 0;



Queued, thanks.  I'll also write a testcase.

Paolo



Re: [PATCH v2] KVM: kvmclock: Fix vCPUs > 64 can't be online/hotpluged

2021-01-27 Thread Wanpeng Li
On Wed, 27 Jan 2021 at 08:28, Wanpeng Li  wrote:
>
> On Wed, 27 Jan 2021 at 01:26, Paolo Bonzini  wrote:
> >
> > On 26/01/21 02:28, Wanpeng Li wrote:
> > > ping,
> > > On Mon, 18 Jan 2021 at 17:08, Wanpeng Li  wrote:
> > >>
> > >> From: Wanpeng Li 
> > >>
> > >> The per-cpu vsyscall pvclock data pointer assigns either an element of 
> > >> the
> > >> static array hv_clock_boot (#vCPU <= 64) or dynamically allocated memory
> > >> hvclock_mem (vCPU > 64), the dynamically memory will not be allocated if
> > >> kvmclock vsyscall is disabled, this can result in cpu hotpluged fails in
> > >> kvmclock_setup_percpu() which returns -ENOMEM. This patch fixes it by not
> > >> assigning vsyscall pvclock data pointer if kvmclock vdso_clock_mode is 
> > >> not
> > >> VDSO_CLOCKMODE_PVCLOCK.
> >
> > I am sorry, I still cannot figure out this patch.
> >
> > Is hotplug still broken if kvm vsyscall is enabled?
>
> Just when kvm vsyscall is disabled. :)
>
> # lscpu
> Architecture:   x86_64
> CPU op-mode(s):32-bit, 64-bit
> Byte Order: Little Endian
> CPU(s):   88
> On-line CPU(s) list:   0-63
> Off-line CPU(s) list:  64-87
>
> # cat /proc/cmdline
> BOOT_IMAGE=/vmlinuz-5.10.0-rc3-tlinux2-0050+ root=/dev/mapper/cl-root
> ro rd.lvm.lv=cl/root rhgb quiet console=ttyS0 LANG=en_US
> .UTF-8 no-kvmclock-vsyscall
>
> # echo 1 > /sys/devices/system/cpu/cpu76/online
> -bash: echo: write error: Cannot allocate memory

The original bug report is here.
https://bugzilla.kernel.org/show_bug.cgi?id=210213

Wanpeng


[PATCH] nbd: Fix NULL pointer in flush_workqueue

2021-01-27 Thread Sun Ke
Open /dev/nbdX first, the config_refs will be 1 and
the pointers in nbd_device are still null. Disconnect
/dev/nbdX, then reference a null recv_workq. The
protection by config_refs in nbd_genl_disconnect is useless.

[  656.366194] BUG: kernel NULL pointer dereference, address: 0020
[  656.368943] #PF: supervisor write access in kernel mode
[  656.369844] #PF: error_code(0x0002) - not-present page
[  656.370717] PGD 10cc87067 P4D 10cc87067 PUD 1074b4067 PMD 0
[  656.371693] Oops: 0002 [#1] SMP
[  656.372242] CPU: 5 PID: 7977 Comm: nbd-client Not tainted 
5.11.0-rc5-00040-g76c057c84d28 #1
[  656.373661] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
?-20190727_073836-buildvm-ppc64le-16.ppc.fedoraproject.org-3.fc31 04/01/2014
[  656.375904] RIP: 0010:mutex_lock+0x29/0x60
[  656.376627] Code: 00 0f 1f 44 00 00 55 48 89 fd 48 83 05 6f d7 fe 08 01 e8 
7a c3 ff ff 48 83 05 6a d7 fe 08 01 31 c0 65 48 8b 14 25 00 6d 01 00  48 0f 
b1 55 d
[  656.378934] RSP: 0018:c95eb9b0 EFLAGS: 00010246
[  656.379350] RAX:  RBX:  RCX: 
[  656.379915] RDX: 888104cf2600 RSI: aae8f452 RDI: 0020
[  656.380473] RBP: 0020 R08:  R09: 88813bd6b318
[  656.381039] R10: 00c7 R11: fefefefefefefeff R12: 888102710b40
[  656.381599] R13: c95eb9e0 R14: b2930680 R15: 88810770ef00
[  656.382166] FS:  7fdf117ebb40() GS:88813bd4() 
knlGS:
[  656.382806] CS:  0010 DS:  ES:  CR0: 80050033
[  656.383261] CR2: 0020 CR3: 000100c84000 CR4: 06e0
[  656.383819] DR0:  DR1:  DR2: 
[  656.384370] DR3:  DR6: fffe0ff0 DR7: 0400
[  656.384927] Call Trace:
[  656.385111]  flush_workqueue+0x92/0x6c0
[  656.385395]  nbd_disconnect_and_put+0x81/0xd0
[  656.385716]  nbd_genl_disconnect+0x125/0x2a0
[  656.386034]  genl_family_rcv_msg_doit.isra.0+0x102/0x1b0
[  656.386422]  genl_rcv_msg+0xfc/0x2b0
[  656.386685]  ? nbd_ioctl+0x490/0x490
[  656.386954]  ? genl_family_rcv_msg_doit.isra.0+0x1b0/0x1b0
[  656.387354]  netlink_rcv_skb+0x62/0x180
[  656.387638]  genl_rcv+0x34/0x60
[  656.387874]  netlink_unicast+0x26d/0x590
[  656.388162]  netlink_sendmsg+0x398/0x6c0
[  656.388451]  ? netlink_rcv_skb+0x180/0x180
[  656.388750]  sys_sendmsg+0x1da/0x320
[  656.389038]  ? sys_recvmsg+0x130/0x220
[  656.389334]  ___sys_sendmsg+0x8e/0xf0
[  656.389605]  ? ___sys_recvmsg+0xa2/0xf0
[  656.389889]  ? handle_mm_fault+0x1671/0x21d0
[  656.390201]  __sys_sendmsg+0x6d/0xe0
[  656.390464]  __x64_sys_sendmsg+0x23/0x30
[  656.390751]  do_syscall_64+0x45/0x70
[  656.391017]  entry_SYSCALL_64_after_hwframe+0x44/0xa9

To fix it, just add a check for a non null task_recv in
nbd_genl_disconnect.

Fixes: e9e006f5fcf2 ("nbd: fix max number of supported devs")
Signed-off-by: Sun Ke 
---
 drivers/block/nbd.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 6727358e147d..4f7885966d32 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -2011,12 +2011,20 @@ static int nbd_genl_disconnect(struct sk_buff *skb, 
struct genl_info *info)
   index);
return -EINVAL;
}
+   mutex_lock(>config_lock);
if (!refcount_inc_not_zero(>refs)) {
mutex_unlock(_index_mutex);
+   mutex_unlock(>config_lock);
printk(KERN_ERR "nbd: device at index %d is going down\n",
   index);
return -EINVAL;
}
+   if (!nbd->recv_workq) {
+   mutex_unlock(>config_lock);
+   mutex_unlock(_index_mutex);
+   return -EINVAL;
+   }
+   mutex_unlock(>config_lock);
mutex_unlock(_index_mutex);
if (!refcount_inc_not_zero(>config_refs)) {
nbd_put(nbd);
-- 
2.25.4



[RFC PATCH 19/34] fs/jfs/jfs_logmgr.c: use bio_new in lbmRead

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/jfs/jfs_logmgr.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index 9330eff210e0..4481f3e33a3f 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -1979,17 +1979,14 @@ static int lbmRead(struct jfs_log * log, int pn, struct 
lbuf ** bpp)
 
bp->l_flag |= lbmREAD;
 
-   bio = bio_alloc(GFP_NOFS, 1);
-
-   bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize - 9);
-   bio_set_dev(bio, log->bdev);
+   bio = bio_new(log->bdev, bp->l_blkno << (log->l2bsize - 9),
+   REQ_OP_READ, 0, 1, GFP_NOFS);
 
bio_add_page(bio, bp->l_page, LOGPSIZE, bp->l_offset);
BUG_ON(bio->bi_iter.bi_size != LOGPSIZE);
 
bio->bi_end_io = lbmIODone;
bio->bi_private = bp;
-   bio->bi_opf = REQ_OP_READ;
/*check if journaling to disk has been disabled*/
if (log->no_integrity) {
bio->bi_iter.bi_size = 0;
-- 
2.22.1



Re: [PATCH v11 4/9] drm/mediatek: add mtk_dither_set_common() function

2021-01-27 Thread CK Hu
On Thu, 2021-01-28 at 15:27 +0800, Hsin-Yi Wang wrote:
> Current implementation of mtk_dither_set() cast dev data to
> struct mtk_ddp_comp_dev. But other devices with different dev data
> would also call this function.
> 
> Separate necessary parameters out so other device components (dither,
> gamma) can call this function.

Reviewed-by: CK Hu 

> 
> Signed-off-by: Hsin-Yi Wang 
> ---
>  drivers/gpu/drm/mediatek/mtk_disp_drv.h |  4 
>  drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 25 +
>  2 files changed, 20 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_disp_drv.h 
> b/drivers/gpu/drm/mediatek/mtk_disp_drv.h
> index 46d199b7b4a29..c50d5fc9fd349 100644
> --- a/drivers/gpu/drm/mediatek/mtk_disp_drv.h
> +++ b/drivers/gpu/drm/mediatek/mtk_disp_drv.h
> @@ -17,6 +17,10 @@ void mtk_color_config(struct device *dev, unsigned int w,
> unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
>  void mtk_color_start(struct device *dev);
>  
> +void mtk_dither_set_common(void __iomem *regs, struct cmdq_client_reg 
> *cmdq_reg,
> +unsigned int bpc, unsigned int CFG,
> +struct cmdq_pkt *cmdq_pkt);
> +
>  void mtk_dpi_start(struct device *dev);
>  void mtk_dpi_stop(struct device *dev);
>  
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c 
> b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> index 7b5293429426d..53d25823a37cc 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> @@ -151,33 +151,40 @@ static void mtk_ddp_clk_disable(struct device *dev)
>   clk_disable_unprepare(priv->clk);
>  }
>  
> -static void mtk_dither_set(struct device *dev, unsigned int bpc,
> - unsigned int CFG, struct cmdq_pkt *cmdq_pkt)
> -{
> - struct mtk_ddp_comp_dev *priv = dev_get_drvdata(dev);
>  
> +void mtk_dither_set_common(void __iomem *regs, struct cmdq_client_reg 
> *cmdq_reg,
> +unsigned int bpc, unsigned int CFG, struct cmdq_pkt 
> *cmdq_pkt)
> +{
>   /* If bpc equal to 0, the dithering function didn't be enabled */
>   if (bpc == 0)
>   return;
>  
>   if (bpc >= MTK_MIN_BPC) {
> - mtk_ddp_write(cmdq_pkt, 0, >cmdq_reg, priv->regs, 
> DISP_DITHER_5);
> - mtk_ddp_write(cmdq_pkt, 0, >cmdq_reg, priv->regs, 
> DISP_DITHER_7);
> + mtk_ddp_write(cmdq_pkt, 0, cmdq_reg, regs, DISP_DITHER_5);
> + mtk_ddp_write(cmdq_pkt, 0, cmdq_reg, regs, DISP_DITHER_7);
>   mtk_ddp_write(cmdq_pkt,
> DITHER_LSB_ERR_SHIFT_R(MTK_MAX_BPC - bpc) |
> DITHER_ADD_LSHIFT_R(MTK_MAX_BPC - bpc) |
> DITHER_NEW_BIT_MODE,
> -   >cmdq_reg, priv->regs, DISP_DITHER_15);
> +   cmdq_reg, regs, DISP_DITHER_15);
>   mtk_ddp_write(cmdq_pkt,
> DITHER_LSB_ERR_SHIFT_B(MTK_MAX_BPC - bpc) |
> DITHER_ADD_LSHIFT_B(MTK_MAX_BPC - bpc) |
> DITHER_LSB_ERR_SHIFT_G(MTK_MAX_BPC - bpc) |
> DITHER_ADD_LSHIFT_G(MTK_MAX_BPC - bpc),
> -   >cmdq_reg, priv->regs, DISP_DITHER_16);
> - mtk_ddp_write(cmdq_pkt, DISP_DITHERING, >cmdq_reg, 
> priv->regs, CFG);
> +   cmdq_reg, regs, DISP_DITHER_16);
> + mtk_ddp_write(cmdq_pkt, DISP_DITHERING, cmdq_reg, regs, CFG);
>   }
>  }
>  
> +static void mtk_dither_set(struct device *dev, unsigned int bpc,
> + unsigned int CFG, struct cmdq_pkt *cmdq_pkt)
> +{
> + struct mtk_ddp_comp_dev *priv = dev_get_drvdata(dev);
> +
> + mtk_dither_set_common(priv->regs, >cmdq_reg, bpc, CFG, cmdq_pkt);
> +}
> +
>  static void mtk_od_config(struct device *dev, unsigned int w,
> unsigned int h, unsigned int vrefresh,
> unsigned int bpc, struct cmdq_pkt *cmdq_pkt)



[RFC PATCH 16/34] fs/direct-io: use bio_new in dio_bio_alloc

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/crypto/bio.c | 2 +-
 fs/direct-io.c  | 6 ++
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/fs/crypto/bio.c b/fs/crypto/bio.c
index 20dab9bdf098..28cd62ce853e 100644
--- a/fs/crypto/bio.c
+++ b/fs/crypto/bio.c
@@ -148,7 +148,7 @@ int fscrypt_zeroout_range(const struct inode *inode, 
pgoff_t lblk,
return -EINVAL;
 
/* This always succeeds since __GFP_DIRECT_RECLAIM is set. */
-   bio = bio_alloc(inode->i_sb->s_bdev, 0, REQ_OP_WRITE, 0, nr_pages,
+   bio = bio_new(inode->i_sb->s_bdev, 0, REQ_OP_WRITE, 0, nr_pages,
GFP_NOFS);
 
do {
diff --git a/fs/direct-io.c b/fs/direct-io.c
index aa1083ecd623..6aab1bd167bc 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -397,11 +397,9 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio,
 * bio_alloc() is guaranteed to return a bio when allowed to sleep and
 * we request a valid number of vectors.
 */
-   bio = bio_alloc(GFP_KERNEL, nr_vecs);
+   bio = bio_new(bdev, first_sector, dio->op, dio->op_flags, nr_vecs,
+ GFP_KERNEL);
 
-   bio_set_dev(bio, bdev);
-   bio->bi_iter.bi_sector = first_sector;
-   bio_set_op_attrs(bio, dio->op, dio->op_flags);
if (dio->is_async)
bio->bi_end_io = dio_bio_end_aio;
else
-- 
2.22.1



[RFC PATCH 17/34] iomap: use bio_new in iomap_dio_zero

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/iomap/direct-io.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index ea1e8f696076..f6c557a1bd25 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -189,15 +189,13 @@ iomap_dio_zero(struct iomap_dio *dio, struct iomap 
*iomap, loff_t pos,
int flags = REQ_SYNC | REQ_IDLE;
struct bio *bio;
 
-   bio = bio_alloc(GFP_KERNEL, 1);
-   bio_set_dev(bio, iomap->bdev);
-   bio->bi_iter.bi_sector = iomap_sector(iomap, pos);
+   bio = bio_new(iomap->bdev, iomap_sector(iomap, pos), REQ_OP_WRITE,
+ flags, 1, GFP_KERNEL);
bio->bi_private = dio;
bio->bi_end_io = iomap_dio_bio_end_io;
 
get_page(page);
__bio_add_page(bio, page, len, 0);
-   bio_set_op_attrs(bio, REQ_OP_WRITE, flags);
iomap_dio_submit_bio(dio, iomap, bio, pos);
 }
 
-- 
2.22.1



[RFC PATCH 18/34] iomap: use bio_new in iomap_dio_bio_actor

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/iomap/direct-io.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index f6c557a1bd25..0737192f7e5c 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -267,9 +267,8 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t 
length,
goto out;
}
 
-   bio = bio_alloc(GFP_KERNEL, nr_pages);
-   bio_set_dev(bio, iomap->bdev);
-   bio->bi_iter.bi_sector = iomap_sector(iomap, pos);
+   bio = bio_new(iomap->bdev, iomap_sector(iomap, pos), 0, 0,
+ nr_pages, GFP_KERNEL);
bio->bi_write_hint = dio->iocb->ki_hint;
bio->bi_ioprio = dio->iocb->ki_ioprio;
bio->bi_private = dio;
-- 
2.22.1



Re: [PATCH 1/2] qspinlock: Ensure writes are pushed out of core write buffer

2021-01-27 Thread Alexander Sverdlin
Hi!

On 27/01/2021 23:21, Will Deacon wrote:
> On Wed, Jan 27, 2021 at 09:01:08PM +0100, Alexander A Sverdlin wrote:
>> From: Alexander Sverdlin 
>>
>> Ensure writes are pushed out of core write buffer to prevent waiting code
>> on another cores from spinning longer than necessary.
>>
>> 6 threads running tight spinlock loop competing for the same lock
>> on 6 cores on MIPS/Octeon do 100 iterations...
>>
>> before the patch in: 4.3 sec
>> after the patch in:  1.2 sec
> If you only have 6 cores, I'm not sure qspinlock makes any sense...

That's my impression as well and I even proposed to revert qspinlocks for MIPS:
https://lore.kernel.org/linux-mips/20170610002644.8434-1-paul.bur...@imgtec.com/T/#ma1506c80472129b2ac41554cc2d863c9a24518c0

>> Same 6-core Octeon machine:
>> sysbench --test=mutex --num-threads=64 --memory-scope=local run
>>
>> w/o patch:   1.53s
>> with patch:  1.28s
>>
>> This will also allow to remove the smp_wmb() in
>> arch/arm/include/asm/mcs_spinlock.h (was it actually addressing the same
>> issue?).
>>
>> Finally our internal quite diverse test suite of different IPC/network
>> aspects didn't detect any regressions on ARM/ARM64/x86_64.
>>
>> Signed-off-by: Alexander Sverdlin 
>> ---
>>  kernel/locking/mcs_spinlock.h | 5 +
>>  kernel/locking/qspinlock.c| 6 ++
>>  2 files changed, 11 insertions(+)
>>
>> diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
>> index 5e10153..10e497a 100644
>> --- a/kernel/locking/mcs_spinlock.h
>> +++ b/kernel/locking/mcs_spinlock.h
>> @@ -89,6 +89,11 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct 
>> mcs_spinlock *node)
>>  return;
>>  }
>>  WRITE_ONCE(prev->next, node);
>> +/*
>> + * This is necessary to make sure that the corresponding "while" in the
>> + * mcs_spin_unlock() doesn't loop forever
>> + */
>> +smp_wmb();
> If it loops forever, that's broken hardware design; store buffers need to
> drain. I don't think we should add unconditional barriers to bodge this.

The comment is a bit exaggerating the situation, but it's undeterministic and 
you see the
measurements above. Something is wrong in the qspinlocks code, please consider 
this patch
"RFC", but something has to be done here.

-- 
Best regards,
Alexander Sverdlin.


[PATCH v11 4/9] drm/mediatek: add mtk_dither_set_common() function

2021-01-27 Thread Hsin-Yi Wang
Current implementation of mtk_dither_set() cast dev data to
struct mtk_ddp_comp_dev. But other devices with different dev data
would also call this function.

Separate necessary parameters out so other device components (dither,
gamma) can call this function.

Signed-off-by: Hsin-Yi Wang 
---
 drivers/gpu/drm/mediatek/mtk_disp_drv.h |  4 
 drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 25 +
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_disp_drv.h 
b/drivers/gpu/drm/mediatek/mtk_disp_drv.h
index 46d199b7b4a29..c50d5fc9fd349 100644
--- a/drivers/gpu/drm/mediatek/mtk_disp_drv.h
+++ b/drivers/gpu/drm/mediatek/mtk_disp_drv.h
@@ -17,6 +17,10 @@ void mtk_color_config(struct device *dev, unsigned int w,
  unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
 void mtk_color_start(struct device *dev);
 
+void mtk_dither_set_common(void __iomem *regs, struct cmdq_client_reg 
*cmdq_reg,
+  unsigned int bpc, unsigned int CFG,
+  struct cmdq_pkt *cmdq_pkt);
+
 void mtk_dpi_start(struct device *dev);
 void mtk_dpi_stop(struct device *dev);
 
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c 
b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
index 7b5293429426d..53d25823a37cc 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
@@ -151,33 +151,40 @@ static void mtk_ddp_clk_disable(struct device *dev)
clk_disable_unprepare(priv->clk);
 }
 
-static void mtk_dither_set(struct device *dev, unsigned int bpc,
-   unsigned int CFG, struct cmdq_pkt *cmdq_pkt)
-{
-   struct mtk_ddp_comp_dev *priv = dev_get_drvdata(dev);
 
+void mtk_dither_set_common(void __iomem *regs, struct cmdq_client_reg 
*cmdq_reg,
+  unsigned int bpc, unsigned int CFG, struct cmdq_pkt 
*cmdq_pkt)
+{
/* If bpc equal to 0, the dithering function didn't be enabled */
if (bpc == 0)
return;
 
if (bpc >= MTK_MIN_BPC) {
-   mtk_ddp_write(cmdq_pkt, 0, >cmdq_reg, priv->regs, 
DISP_DITHER_5);
-   mtk_ddp_write(cmdq_pkt, 0, >cmdq_reg, priv->regs, 
DISP_DITHER_7);
+   mtk_ddp_write(cmdq_pkt, 0, cmdq_reg, regs, DISP_DITHER_5);
+   mtk_ddp_write(cmdq_pkt, 0, cmdq_reg, regs, DISP_DITHER_7);
mtk_ddp_write(cmdq_pkt,
  DITHER_LSB_ERR_SHIFT_R(MTK_MAX_BPC - bpc) |
  DITHER_ADD_LSHIFT_R(MTK_MAX_BPC - bpc) |
  DITHER_NEW_BIT_MODE,
- >cmdq_reg, priv->regs, DISP_DITHER_15);
+ cmdq_reg, regs, DISP_DITHER_15);
mtk_ddp_write(cmdq_pkt,
  DITHER_LSB_ERR_SHIFT_B(MTK_MAX_BPC - bpc) |
  DITHER_ADD_LSHIFT_B(MTK_MAX_BPC - bpc) |
  DITHER_LSB_ERR_SHIFT_G(MTK_MAX_BPC - bpc) |
  DITHER_ADD_LSHIFT_G(MTK_MAX_BPC - bpc),
- >cmdq_reg, priv->regs, DISP_DITHER_16);
-   mtk_ddp_write(cmdq_pkt, DISP_DITHERING, >cmdq_reg, 
priv->regs, CFG);
+ cmdq_reg, regs, DISP_DITHER_16);
+   mtk_ddp_write(cmdq_pkt, DISP_DITHERING, cmdq_reg, regs, CFG);
}
 }
 
+static void mtk_dither_set(struct device *dev, unsigned int bpc,
+   unsigned int CFG, struct cmdq_pkt *cmdq_pkt)
+{
+   struct mtk_ddp_comp_dev *priv = dev_get_drvdata(dev);
+
+   mtk_dither_set_common(priv->regs, >cmdq_reg, bpc, CFG, cmdq_pkt);
+}
+
 static void mtk_od_config(struct device *dev, unsigned int w,
  unsigned int h, unsigned int vrefresh,
  unsigned int bpc, struct cmdq_pkt *cmdq_pkt)
-- 
2.30.0.280.ga3ce27912f-goog



[PATCH v11 5/9] drm/mediatek: separate gamma module

2021-01-27 Thread Hsin-Yi Wang
From: Yongqiang Niu 

mt8183 gamma module will different with mt8173
separate gamma for add private data

Signed-off-by: Yongqiang Niu 
Signed-off-by: Hsin-Yi Wang 
Reviewed-by: CK Hu 
---
 drivers/gpu/drm/mediatek/Makefile   |   1 +
 drivers/gpu/drm/mediatek/mtk_disp_drv.h |  10 ++
 drivers/gpu/drm/mediatek/mtk_disp_gamma.c   | 189 
 drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c |  71 ++--
 drivers/gpu/drm/mediatek/mtk_drm_drv.c  |   4 +-
 drivers/gpu/drm/mediatek/mtk_drm_drv.h  |   1 +
 6 files changed, 215 insertions(+), 61 deletions(-)
 create mode 100644 drivers/gpu/drm/mediatek/mtk_disp_gamma.c

diff --git a/drivers/gpu/drm/mediatek/Makefile 
b/drivers/gpu/drm/mediatek/Makefile
index 01d06332f7679..b64674b944860 100644
--- a/drivers/gpu/drm/mediatek/Makefile
+++ b/drivers/gpu/drm/mediatek/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 mediatek-drm-y := mtk_disp_color.o \
+ mtk_disp_gamma.o \
  mtk_disp_ovl.o \
  mtk_disp_rdma.o \
  mtk_drm_crtc.o \
diff --git a/drivers/gpu/drm/mediatek/mtk_disp_drv.h 
b/drivers/gpu/drm/mediatek/mtk_disp_drv.h
index c50d5fc9fd349..c1e658b490b6c 100644
--- a/drivers/gpu/drm/mediatek/mtk_disp_drv.h
+++ b/drivers/gpu/drm/mediatek/mtk_disp_drv.h
@@ -27,6 +27,16 @@ void mtk_dpi_stop(struct device *dev);
 void mtk_dsi_ddp_start(struct device *dev);
 void mtk_dsi_ddp_stop(struct device *dev);
 
+int mtk_gamma_clk_enable(struct device *dev);
+void mtk_gamma_clk_disable(struct device *dev);
+void mtk_gamma_config(struct device *dev, unsigned int w,
+  unsigned int h, unsigned int vrefresh,
+  unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
+void mtk_gamma_set(struct device *dev, struct drm_crtc_state *state);
+void mtk_gamma_set_common(void __iomem *regs, struct drm_crtc_state *state);
+void mtk_gamma_start(struct device *dev);
+void mtk_gamma_stop(struct device *dev);
+
 void mtk_ovl_bgclr_in_on(struct device *dev);
 void mtk_ovl_bgclr_in_off(struct device *dev);
 void mtk_ovl_bypass_shadow(struct device *dev);
diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c 
b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
new file mode 100644
index 0..a7e2e326b2183
--- /dev/null
+++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
@@ -0,0 +1,189 @@
+/*
+ * SPDX-License-Identifier:
+ *
+ * Copyright (c) 2020 MediaTek Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mtk_disp_drv.h"
+#include "mtk_drm_crtc.h"
+#include "mtk_drm_ddp_comp.h"
+
+#define DISP_GAMMA_EN  0x
+#define GAMMA_EN   BIT(0)
+#define DISP_GAMMA_CFG 0x0020
+#define GAMMA_LUT_EN   BIT(1)
+#define DISP_GAMMA_SIZE0x0030
+#define DISP_GAMMA_LUT 0x0700
+
+#define LUT_10BIT_MASK 0x03ff
+
+struct mtk_disp_gamma_data {
+   u32 reserved;
+};
+
+/**
+ * struct mtk_disp_gamma - DISP_GAMMA driver structure
+ * @ddp_comp - structure containing type enum and hardware resources
+ * @crtc - associated crtc to report irq events to
+ */
+struct mtk_disp_gamma {
+   struct clk *clk;
+   void __iomem *regs;
+   struct cmdq_client_reg cmdq_reg;
+   const struct mtk_disp_gamma_data *data;
+};
+
+int mtk_gamma_clk_enable(struct device *dev)
+{
+   struct mtk_disp_gamma *gamma = dev_get_drvdata(dev);
+
+   return clk_prepare_enable(gamma->clk);
+}
+
+void mtk_gamma_clk_disable(struct device *dev)
+{
+   struct mtk_disp_gamma *gamma = dev_get_drvdata(dev);
+
+   clk_disable_unprepare(gamma->clk);
+}
+
+void mtk_gamma_set_common(void __iomem *regs, struct drm_crtc_state *state)
+{
+   unsigned int i, reg;
+   struct drm_color_lut *lut;
+   void __iomem *lut_base;
+   u32 word;
+
+   if (state->gamma_lut) {
+   reg = readl(regs + DISP_GAMMA_CFG);
+   reg = reg | GAMMA_LUT_EN;
+   writel(reg, regs + DISP_GAMMA_CFG);
+   lut_base = regs + DISP_GAMMA_LUT;
+   lut = (struct drm_color_lut *)state->gamma_lut->data;
+   for (i = 0; i < MTK_LUT_SIZE; i++) {
+   word = (((lut[i].red >> 6) & LUT_10BIT_MASK) << 20) +
+   (((lut[i].green >> 6) & LUT_10BIT_MASK) << 10) +
+   ((lut[i].blue >> 6) & LUT_10BIT_MASK);
+   writel(word, (lut_base + i * 4));
+   }
+   }
+}
+
+void mtk_gamma_set(struct device *dev, struct drm_crtc_state *state)
+{
+   struct mtk_disp_gamma *gamma = dev_get_drvdata(dev);
+
+   mtk_gamma_set_common(gamma->regs, state);
+}
+
+void mtk_gamma_config(struct device *dev, unsigned int w,
+ unsigned int h, unsigned int vrefresh,
+ unsigned int bpc, 

[PATCH v11 6/9] drm/mediatek: add has_dither private data for gamma

2021-01-27 Thread Hsin-Yi Wang
From: Yongqiang Niu 

Not all SoC has dither function in gamma module.
Add private data to control this function setting.

Signed-off-by: Yongqiang Niu 
Signed-off-by: Hsin-Yi Wang 
Reviewed-by: CK Hu 
---
 drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c 
b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
index a7e2e326b2183..22199ef11f65d 100644
--- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
+++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
@@ -26,7 +26,7 @@
 #define LUT_10BIT_MASK 0x03ff
 
 struct mtk_disp_gamma_data {
-   u32 reserved;
+   bool has_dither;
 };
 
 /**
@@ -92,7 +92,8 @@ void mtk_gamma_config(struct device *dev, unsigned int w,
 
mtk_ddp_write(cmdq_pkt, h << 16 | w, >cmdq_reg, gamma->regs,
  DISP_GAMMA_SIZE);
-   mtk_dither_set_common(gamma->regs, >cmdq_reg, bpc, 
DISP_GAMMA_CFG, cmdq_pkt);
+   if (gamma->data && gamma->data->has_dither)
+   mtk_dither_set_common(gamma->regs, >cmdq_reg, bpc, 
DISP_GAMMA_CFG, cmdq_pkt);
 }
 
 void mtk_gamma_start(struct device *dev)
@@ -172,8 +173,13 @@ static int mtk_disp_gamma_remove(struct platform_device 
*pdev)
return 0;
 }
 
+static const struct mtk_disp_gamma_data mt8173_gamma_driver_data = {
+   .has_dither = true,
+};
+
 static const struct of_device_id mtk_disp_gamma_driver_dt_match[] = {
-   { .compatible = "mediatek,mt8173-disp-gamma"},
+   { .compatible = "mediatek,mt8173-disp-gamma",
+ .data = _gamma_driver_data},
{},
 };
 MODULE_DEVICE_TABLE(of, mtk_disp_gamma_driver_dt_match);
-- 
2.30.0.280.ga3ce27912f-goog



[PATCH v11 8/9] soc: mediatek: add mtk mutex support for MT8183

2021-01-27 Thread Hsin-Yi Wang
From: Yongqiang Niu 

Add mtk mutex support for MT8183 SoC.

Signed-off-by: Yongqiang Niu 
Signed-off-by: Hsin-Yi Wang 
---
 drivers/soc/mediatek/mtk-mutex.c | 50 
 1 file changed, 50 insertions(+)

diff --git a/drivers/soc/mediatek/mtk-mutex.c b/drivers/soc/mediatek/mtk-mutex.c
index f531b119da7a9..b348f962f82a4 100644
--- a/drivers/soc/mediatek/mtk-mutex.c
+++ b/drivers/soc/mediatek/mtk-mutex.c
@@ -14,6 +14,8 @@
 
 #define MT2701_MUTEX0_MOD0 0x2c
 #define MT2701_MUTEX0_SOF0 0x30
+#define MT8183_DISP_MUTEX0_MOD00x30
+#define MT8183_DISP_MUTEX0_SOF00x2c
 
 #define DISP_REG_MUTEX_EN(n)   (0x20 + 0x20 * (n))
 #define DISP_REG_MUTEX(n)  (0x24 + 0x20 * (n))
@@ -37,6 +39,18 @@
 #define MT8167_MUTEX_MOD_DISP_DITHER   15
 #define MT8167_MUTEX_MOD_DISP_UFOE 16
 
+#define MT8183_MUTEX_MOD_DISP_RDMA00
+#define MT8183_MUTEX_MOD_DISP_RDMA11
+#define MT8183_MUTEX_MOD_DISP_OVL0 9
+#define MT8183_MUTEX_MOD_DISP_OVL0_2L  10
+#define MT8183_MUTEX_MOD_DISP_OVL1_2L  11
+#define MT8183_MUTEX_MOD_DISP_WDMA012
+#define MT8183_MUTEX_MOD_DISP_COLOR0   13
+#define MT8183_MUTEX_MOD_DISP_CCORR0   14
+#define MT8183_MUTEX_MOD_DISP_AAL0 15
+#define MT8183_MUTEX_MOD_DISP_GAMMA0   16
+#define MT8183_MUTEX_MOD_DISP_DITHER0  17
+
 #define MT8173_MUTEX_MOD_DISP_OVL0 11
 #define MT8173_MUTEX_MOD_DISP_OVL1 12
 #define MT8173_MUTEX_MOD_DISP_RDMA013
@@ -87,6 +101,11 @@
 #define MT2712_MUTEX_SOF_DSI3  6
 #define MT8167_MUTEX_SOF_DPI0  2
 #define MT8167_MUTEX_SOF_DPI1  3
+#define MT8183_MUTEX_SOF_DSI0  1
+#define MT8183_MUTEX_SOF_DPI0  2
+
+#define MT8183_MUTEX_EOF_DSI0  (MT8183_MUTEX_SOF_DSI0 << 6)
+#define MT8183_MUTEX_EOF_DPI0  (MT8183_MUTEX_SOF_DPI0 << 6)
 
 struct mtk_mutex {
int id;
@@ -181,6 +200,20 @@ static const unsigned int 
mt8173_mutex_mod[DDP_COMPONENT_ID_MAX] = {
[DDP_COMPONENT_WDMA1] = MT8173_MUTEX_MOD_DISP_WDMA1,
 };
 
+static const unsigned int mt8183_mutex_mod[DDP_COMPONENT_ID_MAX] = {
+   [DDP_COMPONENT_AAL0] = MT8183_MUTEX_MOD_DISP_AAL0,
+   [DDP_COMPONENT_CCORR] = MT8183_MUTEX_MOD_DISP_CCORR0,
+   [DDP_COMPONENT_COLOR0] = MT8183_MUTEX_MOD_DISP_COLOR0,
+   [DDP_COMPONENT_DITHER] = MT8183_MUTEX_MOD_DISP_DITHER0,
+   [DDP_COMPONENT_GAMMA] = MT8183_MUTEX_MOD_DISP_GAMMA0,
+   [DDP_COMPONENT_OVL0] = MT8183_MUTEX_MOD_DISP_OVL0,
+   [DDP_COMPONENT_OVL_2L0] = MT8183_MUTEX_MOD_DISP_OVL0_2L,
+   [DDP_COMPONENT_OVL_2L1] = MT8183_MUTEX_MOD_DISP_OVL1_2L,
+   [DDP_COMPONENT_RDMA0] = MT8183_MUTEX_MOD_DISP_RDMA0,
+   [DDP_COMPONENT_RDMA1] = MT8183_MUTEX_MOD_DISP_RDMA1,
+   [DDP_COMPONENT_WDMA0] = MT8183_MUTEX_MOD_DISP_WDMA0,
+};
+
 static const unsigned int mt2712_mutex_sof[MUTEX_SOF_DSI3 + 1] = {
[MUTEX_SOF_SINGLE_MODE] = MUTEX_SOF_SINGLE_MODE,
[MUTEX_SOF_DSI0] = MUTEX_SOF_DSI0,
@@ -198,6 +231,13 @@ static const unsigned int mt8167_mutex_sof[MUTEX_SOF_DSI3 
+ 1] = {
[MUTEX_SOF_DPI1] = MT8167_MUTEX_SOF_DPI1,
 };
 
+/* Add EOF setting so overlay hardware can receive frame done irq */
+static const unsigned int mt8183_mutex_sof[MUTEX_SOF_DSI3 + 1] = {
+   [MUTEX_SOF_SINGLE_MODE] = MUTEX_SOF_SINGLE_MODE,
+   [MUTEX_SOF_DSI0] = MUTEX_SOF_DSI0 | MT8183_MUTEX_EOF_DSI0,
+   [MUTEX_SOF_DPI0] = MT8183_MUTEX_SOF_DPI0 | MT8183_MUTEX_EOF_DPI0,
+};
+
 static const struct mtk_mutex_data mt2701_mutex_driver_data = {
.mutex_mod = mt2701_mutex_mod,
.mutex_sof = mt2712_mutex_sof,
@@ -227,6 +267,14 @@ static const struct mtk_mutex_data 
mt8173_mutex_driver_data = {
.mutex_sof_reg = MT2701_MUTEX0_SOF0,
 };
 
+static const struct mtk_mutex_data mt8183_mutex_driver_data = {
+   .mutex_mod = mt8183_mutex_mod,
+   .mutex_sof = mt8183_mutex_sof,
+   .mutex_mod_reg = MT8183_DISP_MUTEX0_MOD0,
+   .mutex_sof_reg = MT8183_DISP_MUTEX0_SOF0,
+   .no_clk = true,
+};
+
 struct mtk_mutex *mtk_mutex_get(struct device *dev)
 {
struct mtk_mutex_ctx *mtx = dev_get_drvdata(dev);
@@ -457,6 +505,8 @@ static const struct of_device_id mutex_driver_dt_match[] = {
  .data = _mutex_driver_data},
{ .compatible = "mediatek,mt8173-disp-mutex",
  .data = _mutex_driver_data},
+   { .compatible = "mediatek,mt8183-disp-mutex",
+ .data = _mutex_driver_data},
{},
 };
 MODULE_DEVICE_TABLE(of, mutex_driver_dt_match);
-- 
2.30.0.280.ga3ce27912f-goog



[PATCH v11 7/9] drm/mediatek: enable dither function

2021-01-27 Thread Hsin-Yi Wang
From: Yongqiang Niu 

for 5 or 6 bpc panel, we need enable dither function
to improve the display quality

Signed-off-by: Yongqiang Niu 
Signed-off-by: Hsin-Yi Wang 
---
 drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 44 -
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c 
b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
index 8173f709272be..e85625704d611 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
@@ -53,7 +53,9 @@
 #define DITHER_EN  BIT(0)
 #define DISP_DITHER_CFG0x0020
 #define DITHER_RELAY_MODE  BIT(0)
+#define DITHER_ENGINE_EN   BIT(1)
 #define DISP_DITHER_SIZE   0x0030
+#define DITHER_REG(idx)(0x100 + (idx) * 4)
 
 #define LUT_10BIT_MASK 0x03ff
 
@@ -313,8 +315,48 @@ static void mtk_dither_config(struct device *dev, unsigned 
int w,
 {
struct mtk_ddp_comp_dev *priv = dev_get_drvdata(dev);
 
+   bool enable = false;
+
+   /* default value for dither reg 5 to 14 */
+   const u32 dither_setting[] = {
+   0x, /* 5 */
+   0x3002, /* 6 */
+   0x, /* 7 */
+   0x, /* 8 */
+   0x, /* 9 */
+   0x, /* 10 */
+   0x, /* 11 */
+   0x0011, /* 12 */
+   0x, /* 13 */
+   0x, /* 14 */
+   };
+
+   if (bpc == 5 || bpc == 6) {
+   enable = true;
+   mtk_ddp_write(cmdq_pkt,
+ DITHER_LSB_ERR_SHIFT_R(MTK_MAX_BPC - bpc) |
+ DITHER_ADD_LSHIFT_R(MTK_MAX_BPC - bpc) |
+ DITHER_NEW_BIT_MODE,
+ >cmdq_reg, priv->regs, DITHER_REG(15));
+   mtk_ddp_write(cmdq_pkt,
+ DITHER_LSB_ERR_SHIFT_B(MTK_MAX_BPC - bpc) |
+ DITHER_ADD_LSHIFT_B(MTK_MAX_BPC - bpc) |
+ DITHER_LSB_ERR_SHIFT_G(MTK_MAX_BPC - bpc) |
+ DITHER_ADD_LSHIFT_G(MTK_MAX_BPC - bpc),
+ >cmdq_reg, priv->regs, DITHER_REG(16));
+   }
+
+
+   if (enable) {
+   u32 idx;
+
+   for (idx = 0; idx < ARRAY_SIZE(dither_setting); idx++)
+   mtk_ddp_write(cmdq_pkt, dither_setting[idx], 
>cmdq_reg, priv->regs,
+ DITHER_REG(idx + 5));
+   }
+
mtk_ddp_write(cmdq_pkt, h << 16 | w, >cmdq_reg, priv->regs, 
DISP_DITHER_SIZE);
-   mtk_ddp_write(cmdq_pkt, DITHER_RELAY_MODE, >cmdq_reg, priv->regs, 
DISP_DITHER_CFG);
+mtk_ddp_write(cmdq_pkt, enable ? DITHER_ENGINE_EN : DITHER_RELAY_MODE, 
>cmdq_reg, priv->regs, DISP_DITHER_CFG);
 }
 
 static void mtk_dither_start(struct device *dev)
-- 
2.30.0.280.ga3ce27912f-goog



Re: [PATCH] ath9k: Add separate entry for LED triggers to fix module builds

2021-01-27 Thread Kalle Valo
Krzysztof Kozlowski  wrote:

> After commit 72cdab808714 ("ath9k: Do not select MAC80211_LEDS by
> default") a configuration like:
>  - MAC80211_LEDS=y
>  - LEDS_CLASS=m
>  - NEW_LEDS=y
>  - ATH9K=y
> leads to a build failure:
> 
> /usr/bin/ld: drivers/net/wireless/ath/ath9k/gpio.o: in function 
> `ath_deinit_leds':
> drivers/net/wireless/ath/ath9k/gpio.c:69: undefined reference to 
> `led_classdev_unregister'
> /usr/bin/ld: drivers/net/wireless/ath/ath9k/gpio.o: in function 
> `led_classdev_register':
> include/linux/leds.h:190: undefined reference to 
> `led_classdev_register_ext'
> 
> To be able to use LED triggers, the LEDS_CLASS can only be a module
> if ath9k driver is a module as well.
> 
> Reported-by: kernel test robot 
> Fixes: 72cdab808714 ("ath9k: Do not select MAC80211_LEDS by default")
> Signed-off-by: Krzysztof Kozlowski 

I took Arnd's patch instead:

https://patchwork.kernel.org/project/linux-wireless/patch/20210125113654.2408057-1-a...@kernel.org/

But I think we really need the cleanup Arnd proposes during the discussion so
that we have consistent LED handling in wireless drivers. Patches very welcome.

Patch set to Superseded.

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/20201227143034.1134829-1-k...@kernel.org/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches



[PATCH v11 9/9] drm/mediatek: add support for mediatek SOC MT8183

2021-01-27 Thread Hsin-Yi Wang
From: Yongqiang Niu 

1. add ovl private data
2. add rdma private data
3. add gamma privte data
4. add main and external path module for crtc create

Signed-off-by: Yongqiang Niu 
Signed-off-by: Hsin-Yi Wang 
Reviewed-by: CK Hu 
---
 drivers/gpu/drm/mediatek/mtk_disp_gamma.c |  1 +
 drivers/gpu/drm/mediatek/mtk_disp_ovl.c   | 18 +
 drivers/gpu/drm/mediatek/mtk_disp_rdma.c  |  6 +++
 drivers/gpu/drm/mediatek/mtk_drm_drv.c| 45 +++
 4 files changed, 70 insertions(+)

diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c 
b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
index 22199ef11f65d..16f73267bb202 100644
--- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
+++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
@@ -180,6 +180,7 @@ static const struct mtk_disp_gamma_data 
mt8173_gamma_driver_data = {
 static const struct of_device_id mtk_disp_gamma_driver_dt_match[] = {
{ .compatible = "mediatek,mt8173-disp-gamma",
  .data = _gamma_driver_data},
+   { .compatible = "mediatek,mt8183-disp-gamma"},
{},
 };
 MODULE_DEVICE_TABLE(of, mtk_disp_gamma_driver_dt_match);
diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c 
b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
index 1c295c58a5e82..da7e38a28759b 100644
--- a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
+++ b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
@@ -424,11 +424,29 @@ static const struct mtk_disp_ovl_data 
mt8173_ovl_driver_data = {
.fmt_rgb565_is_0 = true,
 };
 
+static const struct mtk_disp_ovl_data mt8183_ovl_driver_data = {
+   .addr = DISP_REG_OVL_ADDR_MT8173,
+   .gmc_bits = 10,
+   .layer_nr = 4,
+   .fmt_rgb565_is_0 = true,
+};
+
+static const struct mtk_disp_ovl_data mt8183_ovl_2l_driver_data = {
+   .addr = DISP_REG_OVL_ADDR_MT8173,
+   .gmc_bits = 10,
+   .layer_nr = 2,
+   .fmt_rgb565_is_0 = true,
+};
+
 static const struct of_device_id mtk_disp_ovl_driver_dt_match[] = {
{ .compatible = "mediatek,mt2701-disp-ovl",
  .data = _ovl_driver_data},
{ .compatible = "mediatek,mt8173-disp-ovl",
  .data = _ovl_driver_data},
+   { .compatible = "mediatek,mt8183-disp-ovl",
+ .data = _ovl_driver_data},
+   { .compatible = "mediatek,mt8183-disp-ovl-2l",
+ .data = _ovl_2l_driver_data},
{},
 };
 MODULE_DEVICE_TABLE(of, mtk_disp_ovl_driver_dt_match);
diff --git a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c 
b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
index 04b9542010b00..29fa5f3a05c30 100644
--- a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
+++ b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
@@ -355,11 +355,17 @@ static const struct mtk_disp_rdma_data 
mt8173_rdma_driver_data = {
.fifo_size = SZ_8K,
 };
 
+static const struct mtk_disp_rdma_data mt8183_rdma_driver_data = {
+   .fifo_size = 5 * SZ_1K,
+};
+
 static const struct of_device_id mtk_disp_rdma_driver_dt_match[] = {
{ .compatible = "mediatek,mt2701-disp-rdma",
  .data = _rdma_driver_data},
{ .compatible = "mediatek,mt8173-disp-rdma",
  .data = _rdma_driver_data},
+   { .compatible = "mediatek,mt8183-disp-rdma",
+ .data = _rdma_driver_data},
{},
 };
 MODULE_DEVICE_TABLE(of, mtk_disp_rdma_driver_dt_match);
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c 
b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index 279d3e6f11563..486e73e675ad5 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -129,6 +129,24 @@ static const enum mtk_ddp_comp_id mt8173_mtk_ddp_ext[] = {
DDP_COMPONENT_DPI0,
 };
 
+static const enum mtk_ddp_comp_id mt8183_mtk_ddp_main[] = {
+   DDP_COMPONENT_OVL0,
+   DDP_COMPONENT_OVL_2L0,
+   DDP_COMPONENT_RDMA0,
+   DDP_COMPONENT_COLOR0,
+   DDP_COMPONENT_CCORR,
+   DDP_COMPONENT_AAL0,
+   DDP_COMPONENT_GAMMA,
+   DDP_COMPONENT_DITHER,
+   DDP_COMPONENT_DSI0,
+};
+
+static const enum mtk_ddp_comp_id mt8183_mtk_ddp_ext[] = {
+   DDP_COMPONENT_OVL_2L1,
+   DDP_COMPONENT_RDMA1,
+   DDP_COMPONENT_DPI0,
+};
+
 static const struct mtk_mmsys_driver_data mt2701_mmsys_driver_data = {
.main_path = mt2701_mtk_ddp_main,
.main_len = ARRAY_SIZE(mt2701_mtk_ddp_main),
@@ -161,6 +179,13 @@ static const struct mtk_mmsys_driver_data 
mt8173_mmsys_driver_data = {
.ext_len = ARRAY_SIZE(mt8173_mtk_ddp_ext),
 };
 
+static const struct mtk_mmsys_driver_data mt8183_mmsys_driver_data = {
+   .main_path = mt8183_mtk_ddp_main,
+   .main_len = ARRAY_SIZE(mt8183_mtk_ddp_main),
+   .ext_path = mt8183_mtk_ddp_ext,
+   .ext_len = ARRAY_SIZE(mt8183_mtk_ddp_ext),
+};
+
 static int mtk_drm_kms_init(struct drm_device *drm)
 {
struct mtk_drm_private *private = drm->dev_private;
@@ -375,12 +400,20 @@ static const struct of_device_id mtk_ddp_comp_dt_ids[] = {
  .data = (void *)MTK_DISP_OVL },
{ .compatible = "mediatek,mt8173-disp-ovl",
  .data = (void *)MTK_DISP_OVL },
+   

mmotm 2021-01-27-23-30 uploaded

2021-01-27 Thread akpm
The mm-of-the-moment snapshot 2021-01-27-23-30 has been uploaded to

   https://www.ozlabs.org/~akpm/mmotm/

mmotm-readme.txt says

README for mm-of-the-moment:

https://www.ozlabs.org/~akpm/mmotm/

This is a snapshot of my -mm patch queue.  Uploaded at random hopefully
more than once a week.

You will need quilt to apply these patches to the latest Linus release (5.x
or 5.x-rcY).  The series file is in broken-out.tar.gz and is duplicated in
https://ozlabs.org/~akpm/mmotm/series

The file broken-out.tar.gz contains two datestamp files: .DATE and
.DATE--mm-dd-hh-mm-ss.  Both contain the string -mm-dd-hh-mm-ss,
followed by the base kernel version against which this patch series is to
be applied.

This tree is partially included in linux-next.  To see which patches are
included in linux-next, consult the `series' file.  Only the patches
within the #NEXT_PATCHES_START/#NEXT_PATCHES_END markers are included in
linux-next.


A full copy of the full kernel tree with the linux-next and mmotm patches
already applied is available through git within an hour of the mmotm
release.  Individual mmotm releases are tagged.  The master branch always
points to the latest release, so it's constantly rebasing.

https://github.com/hnaz/linux-mm

The directory https://www.ozlabs.org/~akpm/mmots/ (mm-of-the-second)
contains daily snapshots of the -mm tree.  It is updated more frequently
than mmotm, and is untested.

A git copy of this tree is also available at

https://github.com/hnaz/linux-mm



This mmotm tree contains the following patches against 5.11-rc5:
(patches marked "*" will be included in linux-next)

  origin.patch
* mm-hugetlbfs-fix-cannot-migrate-the-fallocated-hugetlb-page.patch
* mm-hugetlb-fix-a-race-between-freeing-and-dissolving-the-page.patch
* mm-hugetlb-fix-a-race-between-isolating-and-freeing-page.patch
* mm-hugetlb-remove-vm_bug_on_page-from-page_huge_active.patch
* mm-migrate-do-not-migrate-hugetlb-page-whose-refcount-is-one.patch
* mm-compaction-move-high_pfn-to-the-for-loop-scope.patch
* mm-vmalloc-separate-put-pages-and-flush-vm-flags.patch
* init-gcov-allow-config_constructors-on-uml-to-fix-module-gcov.patch
* mm-thp-fix-madv_remove-deadlock-on-shmem-thp.patch
* memblock-do-not-start-bottom-up-allocations-with-kernel_end.patch
* 
mm-filemap-adding-missing-mem_cgroup_uncharge-to-__add_to_page_cache_locked.patch
* kasan-add-explicit-preconditions-to-kasan_report.patch
* kasan-make-addr_has_metadata-return-true-for-valid-addresses.patch
* ubsan-implement-__ubsan_handle_alignment_assumption.patch
* mm-hugetlb-fix-missing-put_page-in-gather_surplus_pages.patch
* maintainers-mailmap-use-my-kernelorg-address.patch
* mm-rmap-fix-potential-pte_unmap-on-an-not-mapped-pte.patch
* proc-kpageflags-prevent-an-integer-overflow-in-stable_page_flags.patch
* proc-kpageflags-do-not-use-uninitialized-struct-pages.patch
* revert-mm-memcontrol-avoid-workload-stalls-when-lowering-memoryhigh.patch
* hexagon-remove-config_experimental-from-defconfigs.patch
* scripts-spellingtxt-increase-error-prone-spell-checking.patch
* scripts-spellingtxt-increase-error-prone-spell-checking-2.patch
* scripts-spellingtxt-add-allocted-and-exeeds-typo.patch
* ntfs-layouth-delete-duplicated-words.patch
* ocfs2-remove-redundant-conditional-before-iput.patch
* ocfs2-cleanup-some-definitions-which-is-not-used-anymore.patch
* ocfs2-clear-links-count-in-ocfs2_mknod-if-an-error-occurs.patch
* ocfs2-fix-ocfs2-corrupt-when-iputting-an-inode.patch
* fs-delete-repeated-words-in-comments.patch
* ramfs-support-o_tmpfile.patch
* kernel-watchdog-flush-all-printk-nmi-buffers-when-hardlockup-detected.patch
  mm.patch
* mm-tracing-record-slab-name-for-kmem_cache_free.patch
* mm-remove-ctor-argument-from-kmem_cache_flags.patch
* mm-slub-disable-user-tracing-for-kmemleak-caches-by-default.patch
* mm-slub-stop-freeing-kmem_cache_node-structures-on-node-offline.patch
* mm-slab-slub-stop-taking-memory-hotplug-lock.patch
* mm-slab-slub-stop-taking-cpu-hotplug-lock.patch
* mm-slub-splice-cpu-and-page-freelists-in-deactivate_slab.patch
* 
mm-slub-remove-slub_memcg_sysfs-boot-param-and-config_slub_memcg_sysfs_on.patch
* mm-debug-improve-memcg-debugging.patch
* 
mm-debug_vm_pgtable-basic-add-validation-for-dirtiness-after-write-protect.patch
* mm-debug_vm_pgtable-basic-iterate-over-entire-protection_map.patch
* mm-page_owner-use-helper-function-zone_end_pfn-to-get-end_pfn.patch
* mm-msync-exit-early-when-the-flags-is-an-ms_async-and-start-vm_start.patch
* 
mm-filemap-remove-unused-parameter-and-change-to-void-type-for-replace_page_cache_page.patch
* mm-filemap-dont-revert-iter-on-eiocbqueued.patch
* mm-filemap-rename-generic_file_buffered_read-subfunctions.patch
* mm-filemap-remove-dynamically-allocated-array-from-filemap_read.patch
* mm-filemap-convert-filemap_get_pages-to-take-a-pagevec.patch
* mm-filemap-use-head-pages-in-generic_file_buffered_read.patch
* mm-filemap-pass-a-sleep-state-to-put_and_wait_on_page_locked.patch
* 

Re: [PATCH v2 5/6] arm64: dts: qcom: Add basic devicetree support for SM8350 SoC

2021-01-27 Thread Sai Prakash Ranjan

Hi Vinod,

On 2021-01-27 21:03, Vinod Koul wrote:

Hi Sai,

On 27-01-21, 18:37, Sai Prakash Ranjan wrote:

Hi Vinod,

On 2021-01-27 18:00, Vinod Koul wrote:



> +  timer {
> +  compatible = "arm,armv8-timer";
> +  interrupts =  IRQ_TYPE_LEVEL_LOW)>,
> +   ,
> +   ,
> +   ;

The last interrupt should be hypervisor physical interrupt(10) not 
12(hyp

virtual).
It works currently with android bootloaders because the host linux 
kernel

will run
at EL1 and will use EL1 physical timer interrupt(14), but if we ever 
have

the host
kernel run in EL2(for example, chrome) then we will not receive any 
timer

interrupts.


I got these values from downstream and used them as is. I will update
and also check documentation. Thanks for pointing out


Yes looks like lot of SoC dtsi entries in downstream got it wrong.
I see upstream sm8250 also missed this. We learnt it the hard way
spending lot of time debugging why we are not able to reach the
console(because no timer interrupts) during bringup on a system
with kernel running in EL2(with VHE). I will try to reach out to
baseport guys to make sure they take care of it in future.

Thanks,
Sai

--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a 
member

of Code Aurora Forum, hosted by The Linux Foundation


Re: [PATCH] ath9k: fix build error with LEDS_CLASS=m

2021-01-27 Thread Kalle Valo
Arnd Bergmann  wrote:

> From: Arnd Bergmann 
> 
> When CONFIG_ATH9K is built-in but LED support is in a loadable
> module, both ath9k drivers fails to link:
> 
> x86_64-linux-ld: drivers/net/wireless/ath/ath9k/gpio.o: in function 
> `ath_deinit_leds':
> gpio.c:(.text+0x36): undefined reference to `led_classdev_unregister'
> x86_64-linux-ld: drivers/net/wireless/ath/ath9k/gpio.o: in function 
> `ath_init_leds':
> gpio.c:(.text+0x179): undefined reference to `led_classdev_register_ext'
> 
> The problem is that the 'imply' keyword does not enforce any dependency
> but is only a weak hint to Kconfig to enable another symbol from a
> defconfig file.
> 
> Change imply to a 'depends on LEDS_CLASS' that prevents the incorrect
> configuration but still allows building the driver without LED support.
> 
> The 'select MAC80211_LEDS' is now ensures that the LED support is
> actually used if it is present, and the added Kconfig dependency
> on MAC80211_LEDS ensures that it cannot be enabled manually when it
> has no effect.
> 
> Fixes: 197f466e93f5 ("ath9k_htc: Do not select MAC80211_LEDS by default")
> Signed-off-by: Arnd Bergmann 
> Acked-by: Johannes Berg 

Patch applied to wireless-drivers.git, thanks.

b64acb28da83 ath9k: fix build error with LEDS_CLASS=m

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/20210125113654.2408057-1-a...@kernel.org/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches



[PATCH v11 3/9] drm/mediatek: add RDMA fifo size error handle

2021-01-27 Thread Hsin-Yi Wang
From: Yongqiang Niu 

This patch add RDMA fifo size error handle
rdma fifo size will not always bigger than the calculated threshold
if that case happened, we need set fifo size as the threshold

Signed-off-by: Yongqiang Niu 
Signed-off-by: Hsin-Yi Wang 
---
 drivers/gpu/drm/mediatek/mtk_disp_rdma.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c 
b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
index b84004394970f..04b9542010b00 100644
--- a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
+++ b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
@@ -168,6 +168,10 @@ void mtk_rdma_config(struct device *dev, unsigned int 
width,
 * account for blanking, and with a pixel depth of 4 bytes:
 */
threshold = width * height * vrefresh * 4 * 7 / 100;
+
+   if (threshold > rdma_fifo_size)
+   threshold = rdma_fifo_size;
+
reg = RDMA_FIFO_UNDERFLOW_EN |
  RDMA_FIFO_PSEUDO_SIZE(rdma_fifo_size) |
  RDMA_OUTPUT_VALID_FIFO_THRESHOLD(threshold);
-- 
2.30.0.280.ga3ce27912f-goog



[RFC PATCH 21/34] fs/jfs/jfs_metapage.c: use bio_new in metapage_writepage

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/jfs/jfs_metapage.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c
index 176580f54af9..3fa09d9a0b94 100644
--- a/fs/jfs/jfs_metapage.c
+++ b/fs/jfs/jfs_metapage.c
@@ -416,12 +416,11 @@ static int metapage_writepage(struct page *page, struct 
writeback_control *wbc)
}
len = min(xlen, (int)JFS_SBI(inode->i_sb)->nbperpage);
 
-   bio = bio_alloc(GFP_NOFS, 1);
-   bio_set_dev(bio, inode->i_sb->s_bdev);
-   bio->bi_iter.bi_sector = pblock << (inode->i_blkbits - 9);
+   bio = bio_new(inode->i_sb->s_bdev,
+ pblock << (inode->i_blkbits - 9), REQ_OP_WRITE,
+ 0, 1, GFP_NOFS);
bio->bi_end_io = metapage_write_end_io;
bio->bi_private = page;
-   bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
 
/* Don't call bio_add_page yet, we may add to this vec */
bio_offset = offset;
-- 
2.22.1



Re: [PATCH 3/6] MIPS: Octeon: qspinlock: Flush write buffer

2021-01-27 Thread Alexander Sverdlin
Hi!

On 27/01/2021 23:34, Peter Zijlstra wrote:
> On Wed, Jan 27, 2021 at 09:36:24PM +0100, Alexander A Sverdlin wrote:
>> From: Alexander Sverdlin 
>>
>> Flushing the write buffer brings aroung 10% performace on the tight
>> uncontended spinlock loops on Octeon. Refer to commit 500c2e1fdbcc
>> ("MIPS: Optimize spinlocks.").
> No objection to the patch, but I don't find the above referenced commit
> to be enlightening wrt nudge_writes(). The best it has to offer is the
> comment that's already in the code.

My point was that original MIPS spinlocks had this write-buffer-flush and
it got lost on the conversion to qspinlocks. The referenced commit just
allows to see the last MIPS-specific implementation before deletion.

>> Signed-off-by: Alexander Sverdlin 
>> ---
>>  arch/mips/include/asm/spinlock.h | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/arch/mips/include/asm/spinlock.h 
>> b/arch/mips/include/asm/spinlock.h
>> index 8a88eb2..0a707f3 100644
>> --- a/arch/mips/include/asm/spinlock.h
>> +++ b/arch/mips/include/asm/spinlock.h
>> @@ -24,6 +24,9 @@ static inline void queued_spin_unlock(struct qspinlock 
>> *lock)
>>  /* This could be optimised with ARCH_HAS_MMIOWB */
>>  mmiowb();
>>  smp_store_release(>locked, 0);
>> +#ifdef CONFIG_CPU_CAVIUM_OCTEON
>> +nudge_writes();
>> +#endif
>>  }
>>  
>>  #include 

-- 
Best regards,
Alexander Sverdlin.


[PATCH v11 0/9] drm/mediatek: add support for mediatek SOC MT8183

2021-01-27 Thread Hsin-Yi Wang
This series is based on kernel/git/chunkuang.hu/linux.git mediatek-drm-next
The series is tested on a mt8183 krane device.

Change since v10
- fix review comments in v9

Change since v9
- change several function to rebase to mediatek-drm-next

Change since v8
- fix some review comment in v8
- separate gamma module for mt8183 has no dither function in gamma
- enable dither function for 5 or 6 bpc panel display
- separate ddp mutex patch from the whole Soc patch

Change since v7
- add dt-binding for mt8183 display
- base mmsys patch
https://patchwork.kernel.org/project/linux-mediatek/cover/1607506379-10998-1-git-send-email-yongqiang@mediatek.com/
- base dts patch
https://patchwork.kernel.org/project/linux-mediatek/cover/20201127104930.1981497-1-enric.balle...@collabora.com/
- add mt8183 function call for setting the routing registers
- add RDMA fifo size error handle

Change since v6
- move ddp component define into mtk_mmsys.h
- add mmsys private data to support different ic path connection
- add mt8183-mmsys.c to support 8183 path connection
- fix reviewed issue in v6

Change since v5
- fix reviewed issue in v5
base https://patchwork.kernel.org/project/linux-mediatek/list/?series=213219

Change since v4
- fix reviewed issue in v4

Change since v3
- fix reviewed issue in v3
- fix type error in v3
- fix conflict with iommu patch

Change since v2
- fix reviewed issue in v2
- add mutex node into dts file

Changes since v1:
- fix reviewed issue in v1
- add dts for mt8183 display nodes
- adjust display clock control flow in patch 22
- add vmap support for mediatek drm in patch 23
- fix page offset issue for mmap function in patch 24
- enable allow_fb_modifiers for mediatek drm in patch 25


Hsin-Yi Wang (1):
  drm/mediatek: add mtk_dither_set_common() function

Yongqiang Niu (8):
  arm64: dts: mt8183: rename rdma fifo size
  arm64: dts: mt8183: refine gamma compatible name
  drm/mediatek: add RDMA fifo size error handle
  drm/mediatek: separate gamma module
  drm/mediatek: add has_dither private data for gamma
  drm/mediatek: enable dither function
  soc: mediatek: add mtk mutex support for MT8183
  drm/mediatek: add support for mediatek SOC MT8183

 arch/arm64/boot/dts/mediatek/mt8183.dtsi|   7 +-
 drivers/gpu/drm/mediatek/Makefile   |   1 +
 drivers/gpu/drm/mediatek/mtk_disp_drv.h |  14 ++
 drivers/gpu/drm/mediatek/mtk_disp_gamma.c   | 196 
 drivers/gpu/drm/mediatek/mtk_disp_ovl.c |  18 ++
 drivers/gpu/drm/mediatek/mtk_disp_rdma.c|  10 +
 drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 138 +++---
 drivers/gpu/drm/mediatek/mtk_drm_drv.c  |  49 -
 drivers/gpu/drm/mediatek/mtk_drm_drv.h  |   1 +
 drivers/soc/mediatek/mtk-mutex.c|  50 +
 10 files changed, 410 insertions(+), 74 deletions(-)
 create mode 100644 drivers/gpu/drm/mediatek/mtk_disp_gamma.c

-- 
2.30.0.280.ga3ce27912f-goog



[PATCH v11 1/9] arm64: dts: mt8183: rename rdma fifo size

2021-01-27 Thread Hsin-Yi Wang
From: Yongqiang Niu 

property name must include only lowercase and '-'

Signed-off-by: Yongqiang Niu 
Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Chun-Kuang Hu 
---
 arch/arm64/boot/dts/mediatek/mt8183.dtsi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt8183.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
index 5b782a4769e7e..6c84ccb709af6 100644
--- a/arch/arm64/boot/dts/mediatek/mt8183.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
@@ -1011,7 +1011,7 @@ rdma0: rdma@1400b000 {
clocks = < CLK_MM_DISP_RDMA0>;
iommus = < M4U_PORT_DISP_RDMA0>;
mediatek,larb = <>;
-   mediatek,rdma_fifo_size = <5120>;
+   mediatek,rdma-fifo-size = <5120>;
mediatek,gce-client-reg = < SUBSYS_1400 0xb000 
0x1000>;
};
 
@@ -1023,7 +1023,7 @@ rdma1: rdma@1400c000 {
clocks = < CLK_MM_DISP_RDMA1>;
iommus = < M4U_PORT_DISP_RDMA1>;
mediatek,larb = <>;
-   mediatek,rdma_fifo_size = <2048>;
+   mediatek,rdma-fifo-size = <2048>;
mediatek,gce-client-reg = < SUBSYS_1400 0xc000 
0x1000>;
};
 
-- 
2.30.0.280.ga3ce27912f-goog



RE: kdump always hangs in rcu_barrier() -> wait_for_completion()

2021-01-27 Thread Dexuan Cui
> From: Paul E. McKenney 
> Sent: Thursday, November 26, 2020 3:55 PM
> To: Dexuan Cui 
> Cc: boqun.f...@gmail.com; Ingo Molnar ;
> r...@vger.kernel.org; vkuznets ; Michael Kelley
> ; linux-kernel@vger.kernel.org
> Subject: Re: kdump always hangs in rcu_barrier() -> wait_for_completion()
> 
> On Thu, Nov 26, 2020 at 10:59:19PM +, Dexuan Cui wrote:
> > > From: Paul E. McKenney 
> > > Sent: Thursday, November 26, 2020 1:42 PM
> > >
> > > > > Another possibility is that rcu_state.gp_kthread is non-NULL, but that
> > > > > something else is preventing RCU grace periods from completing, but in
> > > >
> > > > It looks like somehow the scheduling is not working here: in 
> > > > rcu_barrier()
> > > > , if I replace the wait_for_completion() with
> > > > wait_for_completion_timeout(_state.barrier_completion, 30*HZ),
> the
> > > > issue persists.
> > >
> > > Have you tried using sysreq-t to see what the various tasks are doing?
> >
> > Will try it.
> >
> > BTW, this is a "Generation 2" VM on Hyper-V, meaning sysrq only starts to
> > work after the Hyper-V para-virtualized keyboard driver loads... So, at this
> > early point, sysrq is not working. :-( I'll have to hack the code and use a
> > virtual NMI interrupt to force the sysrq handler to be called.
> 
> Whatever works!
> 
> > > Having interrupts disabled on all CPUs would have the effect of disabling
> > > the RCU CPU stall warnings.
> > >   Thanx, Paul
> >
> > I'm sure the interrupts are not disabled. Here the VM only has 1 virtual 
> > CPU,
> > and when the hang issue happens the virtual serial console is still 
> > responding
> > when I press Enter (it prints a new line) or Ctrl+C (it prints ^C).
> >
> > Here the VM does not use the "legacy timers" (PIT, Local APIC timer, etc.) 
> > at
> all.
> > Instead, the VM uses the Hyper-V para-virtualized timers. It looks the
> Hyper-V
> > timer never fires in the kdump kernel when the hang issue happens. I'm
> > looking into this... I suspect this hang issue may only be specific to 
> > Hyper-V.
> 
> Fair enough, given that timers not working can also suppress RCU CPU
> stall warnings.  ;-)
> 
>   Thanx, Paul

FYI: the issue has been fixed by this fix:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fff7b5e6ee63c5d20406a131b260c619cdd24fd1

Thanks,
-- Dexuan


Re: [RFC PATCH 02/34] block: introduce and use bio_new

2021-01-27 Thread Damien Le Moal
On 2021/01/28 16:21, Damien Le Moal wrote:
> On 2021/01/28 16:12, Chaitanya Kulkarni wrote:
>> Introduce bio_new() helper and use it in blk-lib.c to allocate and
>> initialize various non-optional or semi-optional members of the bio
>> along with bio allocation done with bio_alloc(). Here we also calmp the
>> max_bvecs for bio with BIO_MAX_PAGES before we pass to bio_alloc().
>>
>> Signed-off-by: Chaitanya Kulkarni 
>> ---
>>  block/blk-lib.c |  6 +-
>>  include/linux/bio.h | 25 +
>>  2 files changed, 26 insertions(+), 5 deletions(-)
>>
>> diff --git a/block/blk-lib.c b/block/blk-lib.c
>> index fb486a0bdb58..ec29415f00dd 100644
>> --- a/block/blk-lib.c
>> +++ b/block/blk-lib.c
>> @@ -14,17 +14,13 @@ struct bio *blk_next_bio(struct bio *bio, struct 
>> block_device *bdev,
>>  sector_t sect, unsigned op, unsigned opf,
>>  unsigned int nr_pages, gfp_t gfp)
>>  {
>> -struct bio *new = bio_alloc(gfp, nr_pages);
>> +struct bio *new = bio_new(bdev, sect, op, opf, gfp, nr_pages);
>>  
>>  if (bio) {
>>  bio_chain(bio, new);
>>  submit_bio(bio);
>>  }
>>  
>> -new->bi_iter.bi_sector = sect;
>> -bio_set_dev(new, bdev);
>> -bio_set_op_attrs(new, op, opf);
>> -
>>  return new;
>>  }
>>  
>> diff --git a/include/linux/bio.h b/include/linux/bio.h
>> index c74857cf1252..2a09ba100546 100644
>> --- a/include/linux/bio.h
>> +++ b/include/linux/bio.h
>> @@ -826,5 +826,30 @@ static inline void bio_set_polled(struct bio *bio, 
>> struct kiocb *kiocb)
>>  if (!is_sync_kiocb(kiocb))
>>  bio->bi_opf |= REQ_NOWAIT;
>>  }
>> +/**
>> + * bio_new -allcate and initialize new bio
>> + * @bdev:   blockdev to issue discard for
>> + * @sector: start sector
>> + * @op: REQ_OP_XXX from enum req_opf
>> + * @op_flags:   REQ_XXX from enum req_flag_bits
>> + * @max_bvecs:  maximum bvec to be allocated for this bio
>> + * @gfp_mask:   memory allocation flags (for bio_alloc)
>> + *
>> + * Description:
>> + *Allocates, initializes common members, and returns a new bio.
>> + */
>> +static inline struct bio *bio_new(struct block_device *bdev, sector_t 
>> sector,
>> +  unsigned int op, unsigned int op_flags,
>> +  unsigned int max_bvecs, gfp_t gfp_mask)
>> +{
>> +unsigned nr_bvec = clamp_t(unsigned int, max_bvecs, 0, BIO_MAX_PAGES);
>> +struct bio *bio = bio_alloc(gfp_mask, nr_bvec);
> 
> I think that depending on the gfp_mask passed, bio can be NULL. So this should
> be checked.
> 
>> +
>> +bio_set_dev(bio, bdev);
>> +bio->bi_iter.bi_sector = sector;
>> +bio_set_op_attrs(bio, op, op_flags);
> 
> This function is obsolete. Open code this.

And that also mean that you could remove one argument to bio_new(): combine op
and op_flags into "unsigned int opf"

> 
>> +
>> +return bio;
>> +}
>>  
>>  #endif /* __LINUX_BIO_H */
>>
> 
> 


-- 
Damien Le Moal
Western Digital Research


[PATCH v11 2/9] arm64: dts: mt8183: refine gamma compatible name

2021-01-27 Thread Hsin-Yi Wang
From: Yongqiang Niu 

mt8183 gamma is different with mt8173
remove mt8173 compatible name for mt8183 gamma

Signed-off-by: Yongqiang Niu 
Signed-off-by: Hsin-Yi Wang 
---
 arch/arm64/boot/dts/mediatek/mt8183.dtsi | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt8183.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
index 6c84ccb709af6..9c0073cfad452 100644
--- a/arch/arm64/boot/dts/mediatek/mt8183.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
@@ -1055,8 +1055,7 @@ aal0: aal@1401 {
};
 
gamma0: gamma@14011000 {
-   compatible = "mediatek,mt8183-disp-gamma",
-"mediatek,mt8173-disp-gamma";
+   compatible = "mediatek,mt8183-disp-gamma";
reg = <0 0x14011000 0 0x1000>;
interrupts = ;
power-domains = < MT8183_POWER_DOMAIN_DISP>;
-- 
2.30.0.280.ga3ce27912f-goog



Re: [PATCH 1/6] MIPS: Octeon: Implement __smp_store_release()

2021-01-27 Thread Alexander Sverdlin
Hello Peter,

On 27/01/2021 23:32, Peter Zijlstra wrote:
>> Link: https://lore.kernel.org/lkml/5644d08d.4080...@caviumnetworks.com/

please, check the discussion pointed by the link above...

>> Signed-off-by: Alexander Sverdlin 
>> ---
>>  arch/mips/include/asm/barrier.h | 9 +
>>  1 file changed, 9 insertions(+)
>>
>> diff --git a/arch/mips/include/asm/barrier.h 
>> b/arch/mips/include/asm/barrier.h
>> index 49ff172..24c3f2c 100644
>> --- a/arch/mips/include/asm/barrier.h
>> +++ b/arch/mips/include/asm/barrier.h
>> @@ -113,6 +113,15 @@ static inline void wmb(void)
>>  ".set arch=octeon\n\t"  \
>>  "syncw\n\t" \
>>  ".set pop" : : : "memory")
>> +
>> +#define __smp_store_release(p, v)   \
>> +do {
>> \
>> +compiletime_assert_atomic_type(*p); \
>> +__smp_wmb();\
>> +__smp_rmb();\
>> +WRITE_ONCE(*p, v);  \
>> +} while (0)
> This is wrong in general since smp_rmb() will only provide order between
> two loads and smp_store_release() is a store.
> 
> If this is correct for all MIPS, this needs a giant comment on exactly
> how that smp_rmb() makes sense here.

... the macro is provided for Octeon only, and __smp_rmb() is actually a NOP
there, but I thought to "document" the flow of thoughts from the discussion
above by including it anyway.

-- 
Best regards,
Alexander Sverdlin.


Re: [RFC PATCH 28/34] zonefs: use bio_new

2021-01-27 Thread Damien Le Moal
On 2021/01/28 16:15, Chaitanya Kulkarni wrote:
> Signed-off-by: Chaitanya Kulkarni 
> ---
>  fs/zonefs/super.c | 6 ++
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
> index ab68e27bb322..620d67965a22 100644
> --- a/fs/zonefs/super.c
> +++ b/fs/zonefs/super.c
> @@ -661,6 +661,7 @@ static const struct iomap_dio_ops zonefs_write_dio_ops = {
>  
>  static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter 
> *from)
>  {
> + unsigned int op = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE;

I do not see the point of adding this variable since it is used only for the
bio_new() call. Pass the op value directly.

>   struct inode *inode = file_inode(iocb->ki_filp);
>   struct zonefs_inode_info *zi = ZONEFS_I(inode);
>   struct block_device *bdev = inode->i_sb->s_bdev;
> @@ -678,15 +679,12 @@ static ssize_t zonefs_file_dio_append(struct kiocb 
> *iocb, struct iov_iter *from)
>   if (!nr_pages)
>   return 0;
>  
> - bio = bio_alloc(GFP_NOFS, nr_pages);
> + bio = bio_new(bdev, zi->i_zsector, op, 0, GFP_NOFS, nr_pages);
>   if (!bio)
>   return -ENOMEM;
>  
> - bio_set_dev(bio, bdev);
> - bio->bi_iter.bi_sector = zi->i_zsector;
>   bio->bi_write_hint = iocb->ki_hint;
>   bio->bi_ioprio = iocb->ki_ioprio;
> - bio->bi_opf = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE;
>   if (iocb->ki_flags & IOCB_DSYNC)
>   bio->bi_opf |= REQ_FUA;
>  
> 


-- 
Damien Le Moal
Western Digital Research


Re: [RESEND PATCH 1/2] KVM: X86: Add support for the emulation of DR6_BUS_LOCK bit

2021-01-27 Thread Paolo Bonzini

On 28/01/21 08:17, Xiaoyao Li wrote:


"Active low" means that the bit is usually 1 and goes to 0 when the 
condition (such as RTM or bus lock) happens.  For almost all those DR6 
bits the value is in fact always 1, but if they are defined in the 
future it will require no code change.


Why not keep use DR6_INIT, or DR6_RESET_VALUE? or any other better name.

It's just the default clear value of DR6 that no debug condition is hit.


I preferred "DR6_ACTIVE_LOW" because the value is used only once or 
twice to initialize dr6, and many times to invert those bits.  For example:


vcpu->arch.dr6 &= ~DR_TRAP_BITS;
vcpu->arch.dr6 |= DR6_ACTIVE_LOW;
vcpu->arch.dr6 |= payload;
vcpu->arch.dr6 ^= payload & DR6_ACTIVE_LOW;

payload = vcpu->arch.dr6;
payload &= ~DR6_BT;
payload ^= DR6_ACTIVE_LOW;

The name conveys that it's not just the initialization value; it's also 
the XOR mask between the #DB exit qualification (which we also use as 
the "payload") and DR6.


Paolo



[RFC PATCH 24/34] fs/nilfs: use bio_new nilfs_alloc_seg_bio

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/nilfs2/segbuf.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/fs/nilfs2/segbuf.c b/fs/nilfs2/segbuf.c
index 1e75417bfe6e..df352cab7a93 100644
--- a/fs/nilfs2/segbuf.c
+++ b/fs/nilfs2/segbuf.c
@@ -383,15 +383,9 @@ static int nilfs_segbuf_submit_bio(struct 
nilfs_segment_buffer *segbuf,
 static struct bio *nilfs_alloc_seg_bio(struct the_nilfs *nilfs, sector_t start,
   int nr_vecs)
 {
-   struct bio *bio;
+   sector_t sect = start << (nilfs->ns_blocksize_bits - 9);
 
-   bio = bio_alloc(GFP_NOIO, nr_vecs);
-   if (likely(bio)) {
-   bio_set_dev(bio, nilfs->ns_bdev);
-   bio->bi_iter.bi_sector =
-   start << (nilfs->ns_blocksize_bits - 9);
-   }
-   return bio;
+   return bio_new(nilfs->ns_bdev, sect, 0, 0, nr_vecs, GFP_NOIO);
 }
 
 static void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *segbuf,
-- 
2.22.1



[RFC PATCH 23/34] fs/mpage.c: use bio_new mpage_alloc

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/mpage.c | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/fs/mpage.c b/fs/mpage.c
index 830e6cc2a9e7..01725126e81f 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -68,25 +68,21 @@ static struct bio *mpage_bio_submit(int op, int op_flags, 
struct bio *bio)
 }
 
 static struct bio *
-mpage_alloc(struct block_device *bdev,
-   sector_t first_sector, int nr_vecs,
-   gfp_t gfp_flags)
+mpage_alloc(struct block_device *bdev, sector_t first_sector, int nr_vecs,
+   gfp_t gfp_flags)
 {
struct bio *bio;
 
/* Restrict the given (page cache) mask for slab allocations */
gfp_flags &= GFP_KERNEL;
-   bio = bio_alloc(gfp_flags, nr_vecs);
+   bio = bio_new(bdev, first_sector, 0, 0, nr_vecs, gfp_flags);
 
if (bio == NULL && (current->flags & PF_MEMALLOC)) {
while (!bio && (nr_vecs /= 2))
-   bio = bio_alloc(gfp_flags, nr_vecs);
+   bio = bio_new(bdev, first_sector, 0, 0, nr_vecs,
+   gfp_flags);
}
 
-   if (bio) {
-   bio_set_dev(bio, bdev);
-   bio->bi_iter.bi_sector = first_sector;
-   }
return bio;
 }
 
@@ -304,9 +300,7 @@ static struct bio *do_mpage_readpage(struct 
mpage_readpage_args *args)
goto out;
}
args->bio = mpage_alloc(bdev, blocks[0] << (blkbits - 9),
-   min_t(int, args->nr_pages,
- BIO_MAX_PAGES),
-   gfp);
+   args->nr_pages, gfp);
if (args->bio == NULL)
goto confused;
}
-- 
2.22.1



Re: [PATCH] netdevsim: init u64 stats for 32bit hardware

2021-01-27 Thread Dmitry Vyukov
On Thu, Jan 28, 2021 at 3:43 AM Hillf Danton  wrote:
>
> Init the u64 stats in order to avoid the lockdep prints on the 32bit
> hardware like

FTR this is not just to avoid lockdep prints, but also to prevent very
real stalls in production.
u64_stats_init initializes seqlock, if the uninitialized
selock->sequence would be odd, the kernel will stall.

Maintainers, please send this upstream on your earliest convenience,
this breaks all 32-bit arches for testing purposes.

Thanks

>  INFO: trying to register non-static key.
>  the code is fine but needs lockdep annotation.
>  turning off the locking correctness validator.
>  CPU: 0 PID: 4695 Comm: syz-executor.0 Not tainted 5.11.0-rc5-syzkaller #0
>  Hardware name: ARM-Versatile Express
>  Backtrace:
>  [<826fc5b8>] (dump_backtrace) from [<826fc82c>] (show_stack+0x18/0x1c 
> arch/arm/kernel/traps.c:252)
>  [<826fc814>] (show_stack) from [<8270d1f8>] (__dump_stack 
> lib/dump_stack.c:79 [inline])
>  [<826fc814>] (show_stack) from [<8270d1f8>] (dump_stack+0xa8/0xc8 
> lib/dump_stack.c:120)
>  [<8270d150>] (dump_stack) from [<802bf9c0>] (assign_lock_key 
> kernel/locking/lockdep.c:935 [inline])
>  [<8270d150>] (dump_stack) from [<802bf9c0>] (register_lock_class+0xabc/0xb68 
> kernel/locking/lockdep.c:1247)
>  [<802bef04>] (register_lock_class) from [<802baa2c>] 
> (__lock_acquire+0x84/0x32d4 kernel/locking/lockdep.c:4711)
>  [<802ba9a8>] (__lock_acquire) from [<802be840>] 
> (lock_acquire.part.0+0xf0/0x554 kernel/locking/lockdep.c:5442)
>  [<802be750>] (lock_acquire.part.0) from [<802bed10>] (lock_acquire+0x6c/0x74 
> kernel/locking/lockdep.c:5415)
>  [<802beca4>] (lock_acquire) from [<81560548>] 
> (seqcount_lockdep_reader_access include/linux/seqlock.h:103 [inline])
>  [<802beca4>] (lock_acquire) from [<81560548>] (__u64_stats_fetch_begin 
> include/linux/u64_stats_sync.h:164 [inline])
>  [<802beca4>] (lock_acquire) from [<81560548>] (u64_stats_fetch_begin 
> include/linux/u64_stats_sync.h:175 [inline])
>  [<802beca4>] (lock_acquire) from [<81560548>] (nsim_get_stats64+0xdc/0xf0 
> drivers/net/netdevsim/netdev.c:70)
>  [<8156046c>] (nsim_get_stats64) from [<81e2efa0>] (dev_get_stats+0x44/0xd0 
> net/core/dev.c:10405)
>  [<81e2ef5c>] (dev_get_stats) from [<81e53204>] (rtnl_fill_stats+0x38/0x120 
> net/core/rtnetlink.c:1211)
>  [<81e531cc>] (rtnl_fill_stats) from [<81e59d58>] 
> (rtnl_fill_ifinfo+0x6d4/0x148c net/core/rtnetlink.c:1783)
>  [<81e59684>] (rtnl_fill_ifinfo) from [<81e5ceb4>] 
> (rtmsg_ifinfo_build_skb+0x9c/0x108 net/core/rtnetlink.c:3798)
>  [<81e5ce18>] (rtmsg_ifinfo_build_skb) from [<81e5d0ac>] (rtmsg_ifinfo_event 
> net/core/rtnetlink.c:3830 [inline])
>  [<81e5ce18>] (rtmsg_ifinfo_build_skb) from [<81e5d0ac>] (rtmsg_ifinfo_event 
> net/core/rtnetlink.c:3821 [inline])
>  [<81e5ce18>] (rtmsg_ifinfo_build_skb) from [<81e5d0ac>] 
> (rtmsg_ifinfo+0x44/0x70 net/core/rtnetlink.c:3839)
>  [<81e5d068>] (rtmsg_ifinfo) from [<81e45c2c>] 
> (register_netdevice+0x664/0x68c net/core/dev.c:10103)
>  [<81e455c8>] (register_netdevice) from [<815608bc>] (nsim_create+0xf8/0x124 
> drivers/net/netdevsim/netdev.c:317)
>  [<815607c4>] (nsim_create) from [<81561184>] 
> (__nsim_dev_port_add+0x108/0x188 drivers/net/netdevsim/dev.c:941)
>  [<8156107c>] (__nsim_dev_port_add) from [<815620d8>] (nsim_dev_port_add_all 
> drivers/net/netdevsim/dev.c:990 [inline])
>  [<8156107c>] (__nsim_dev_port_add) from [<815620d8>] 
> (nsim_dev_probe+0x5cc/0x750 drivers/net/netdevsim/dev.c:1119)
>  [<81561b0c>] (nsim_dev_probe) from [<815661dc>] (nsim_bus_probe+0x10/0x14 
> drivers/net/netdevsim/bus.c:287)
>  [<815661cc>] (nsim_bus_probe) from [<811724c0>] (really_probe+0x100/0x50c 
> drivers/base/dd.c:554)
>  [<811723c0>] (really_probe) from [<811729c4>] 
> (driver_probe_device+0xf8/0x1c8 drivers/base/dd.c:740)
>  [<811728cc>] (driver_probe_device) from [<81172fe4>] 
> (__device_attach_driver+0x8c/0xf0 drivers/base/dd.c:846)
>  [<81172f58>] (__device_attach_driver) from [<8116fee0>] 
> (bus_for_each_drv+0x88/0xd8 drivers/base/bus.c:431)
>  [<8116fe58>] (bus_for_each_drv) from [<81172c6c>] 
> (__device_attach+0xdc/0x1d0 drivers/base/dd.c:914)
>  [<81172b90>] (__device_attach) from [<8117305c>] 
> (device_initial_probe+0x14/0x18 drivers/base/dd.c:961)
>  [<81173048>] (device_initial_probe) from [<81171358>] 
> (bus_probe_device+0x90/0x98 drivers/base/bus.c:491)
>  [<811712c8>] (bus_probe_device) from [<8116e77c>] (device_add+0x320/0x824 
> drivers/base/core.c:3109)
>  [<8116e45c>] (device_add) from [<8116ec9c>] (device_register+0x1c/0x20 
> drivers/base/core.c:3182)
>  [<8116ec80>] (device_register) from [<81566710>] (nsim_bus_dev_new 
> drivers/net/netdevsim/bus.c:336 [inline])
>  [<8116ec80>] (device_register) from [<81566710>] 
> (new_device_store+0x178/0x208 drivers/net/netdevsim/bus.c:215)
>  [<81566598>] (new_device_store) from [<8116fcb4>] (bus_attr_store+0x2c/0x38 
> drivers/base/bus.c:122)
>  [<8116fc88>] (bus_attr_store) from [<805b4b8c>] (sysfs_kf_write+0x48/0x54 
> 

[RFC PATCH 26/34] xfs: use bio_new in xfs_rw_bdev

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/xfs/xfs_bio_io.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/xfs/xfs_bio_io.c b/fs/xfs/xfs_bio_io.c
index e2148f2d5d6b..e4644f22ebe6 100644
--- a/fs/xfs/xfs_bio_io.c
+++ b/fs/xfs/xfs_bio_io.c
@@ -26,11 +26,8 @@ xfs_rw_bdev(
if (is_vmalloc && op == REQ_OP_WRITE)
flush_kernel_vmap_range(data, count);
 
-   bio = bio_alloc(GFP_KERNEL, bio_max_vecs(left));
-   bio_set_dev(bio, bdev);
-   bio->bi_iter.bi_sector = sector;
-   bio->bi_opf = op | REQ_META | REQ_SYNC;
-
+   bio = bio_new(bdev, sector, op, REQ_META | REQ_SYNC, bio_max_vecs(left),
+ GFP_KERNEL);
do {
struct page *page = kmem_to_page(data);
unsigned intoff = offset_in_page(data);
-- 
2.22.1



[RFC PATCH 27/34] xfs: use bio_new in xfs_buf_ioapply_map

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/xfs/xfs_buf.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index f8400bbd6473..3ff6235e4f94 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -1507,12 +1507,10 @@ xfs_buf_ioapply_map(
atomic_inc(>b_io_remaining);
nr_pages = min(total_nr_pages, BIO_MAX_PAGES);
 
-   bio = bio_alloc(GFP_NOIO, nr_pages);
-   bio_set_dev(bio, bp->b_target->bt_bdev);
-   bio->bi_iter.bi_sector = sector;
+   bio = bio_new(bp->b_target->bt_bdev, sector, op, 0, nr_pages,
+ GFP_NOIO);
bio->bi_end_io = xfs_buf_bio_end_io;
bio->bi_private = bp;
-   bio->bi_opf = op;
 
for (; size && nr_pages; nr_pages--, page_index++) {
int rbytes, nbytes = PAGE_SIZE - offset;
-- 
2.22.1



Re: [RFC PATCH 02/34] block: introduce and use bio_new

2021-01-27 Thread Damien Le Moal
On 2021/01/28 16:12, Chaitanya Kulkarni wrote:
> Introduce bio_new() helper and use it in blk-lib.c to allocate and
> initialize various non-optional or semi-optional members of the bio
> along with bio allocation done with bio_alloc(). Here we also calmp the
> max_bvecs for bio with BIO_MAX_PAGES before we pass to bio_alloc().
> 
> Signed-off-by: Chaitanya Kulkarni 
> ---
>  block/blk-lib.c |  6 +-
>  include/linux/bio.h | 25 +
>  2 files changed, 26 insertions(+), 5 deletions(-)
> 
> diff --git a/block/blk-lib.c b/block/blk-lib.c
> index fb486a0bdb58..ec29415f00dd 100644
> --- a/block/blk-lib.c
> +++ b/block/blk-lib.c
> @@ -14,17 +14,13 @@ struct bio *blk_next_bio(struct bio *bio, struct 
> block_device *bdev,
>   sector_t sect, unsigned op, unsigned opf,
>   unsigned int nr_pages, gfp_t gfp)
>  {
> - struct bio *new = bio_alloc(gfp, nr_pages);
> + struct bio *new = bio_new(bdev, sect, op, opf, gfp, nr_pages);
>  
>   if (bio) {
>   bio_chain(bio, new);
>   submit_bio(bio);
>   }
>  
> - new->bi_iter.bi_sector = sect;
> - bio_set_dev(new, bdev);
> - bio_set_op_attrs(new, op, opf);
> -
>   return new;
>  }
>  
> diff --git a/include/linux/bio.h b/include/linux/bio.h
> index c74857cf1252..2a09ba100546 100644
> --- a/include/linux/bio.h
> +++ b/include/linux/bio.h
> @@ -826,5 +826,30 @@ static inline void bio_set_polled(struct bio *bio, 
> struct kiocb *kiocb)
>   if (!is_sync_kiocb(kiocb))
>   bio->bi_opf |= REQ_NOWAIT;
>  }
> +/**
> + * bio_new - allcate and initialize new bio
> + * @bdev:blockdev to issue discard for
> + * @sector:  start sector
> + * @op:  REQ_OP_XXX from enum req_opf
> + * @op_flags:REQ_XXX from enum req_flag_bits
> + * @max_bvecs:   maximum bvec to be allocated for this bio
> + * @gfp_mask:memory allocation flags (for bio_alloc)
> + *
> + * Description:
> + *Allocates, initializes common members, and returns a new bio.
> + */
> +static inline struct bio *bio_new(struct block_device *bdev, sector_t sector,
> +   unsigned int op, unsigned int op_flags,
> +   unsigned int max_bvecs, gfp_t gfp_mask)
> +{
> + unsigned nr_bvec = clamp_t(unsigned int, max_bvecs, 0, BIO_MAX_PAGES);
> + struct bio *bio = bio_alloc(gfp_mask, nr_bvec);

I think that depending on the gfp_mask passed, bio can be NULL. So this should
be checked.

> +
> + bio_set_dev(bio, bdev);
> + bio->bi_iter.bi_sector = sector;
> + bio_set_op_attrs(bio, op, op_flags);

This function is obsolete. Open code this.

> +
> + return bio;
> +}
>  
>  #endif /* __LINUX_BIO_H */
> 


-- 
Damien Le Moal
Western Digital Research


[RFC PATCH 30/34] hfsplus: use bio_new in hfsplus_submit_bio()

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/hfsplus/wrapper.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/fs/hfsplus/wrapper.c b/fs/hfsplus/wrapper.c
index 0350dc7821bf..8341ee6c9b31 100644
--- a/fs/hfsplus/wrapper.c
+++ b/fs/hfsplus/wrapper.c
@@ -64,10 +64,7 @@ int hfsplus_submit_bio(struct super_block *sb, sector_t 
sector,
offset = start & (io_size - 1);
sector &= ~((io_size >> HFSPLUS_SECTOR_SHIFT) - 1);
 
-   bio = bio_alloc(GFP_NOIO, 1);
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, sb->s_bdev);
-   bio_set_op_attrs(bio, op, op_flags);
+   bio = bio_new(sb->s_bdev, sector, op, op_flags, 1, GFP_NOIO);
 
if (op != WRITE && data)
*data = (u8 *)buf + offset;
-- 
2.22.1



[RFC PATCH 32/34] mm: use bio_new in __swap_writepage

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 mm/page_io.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index 92f7941c6d01..25b321489703 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -342,10 +342,8 @@ int __swap_writepage(struct page *page, struct 
writeback_control *wbc,
return 0;
}
 
-   bio = bio_alloc(GFP_NOIO, 1);
-   bio_set_dev(bio, sis->bdev);
-   bio->bi_iter.bi_sector = swap_page_sector(page);
-   bio->bi_opf = REQ_OP_WRITE | REQ_SWAP | wbc_to_write_flags(wbc);
+   bio = bio_alloc(sis->bdev, swap_page_sector(page), REQ_OP_WRITE,
+   REQ_SWAP | wbc_to_write_flags(wbc), 1, GFP_NOIO);
bio->bi_end_io = end_write_func;
bio_add_page(bio, page, thp_size(page), 0);
 
-- 
2.22.1



[RFC PATCH 34/34] mm: add swap_bio_new common bio helper

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 mm/page_io.c | 26 --
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index 7579485ccb5e..cc30c9a0b0a7 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -287,6 +287,17 @@ static void bio_associate_blkg_from_page(struct bio *bio, 
struct page *page)
 #define bio_associate_blkg_from_page(bio, page)do { } while (0)
 #endif /* CONFIG_MEMCG && CONFIG_BLK_CGROUP */
 
+static inline struct bio *swap_bio_new(struct block_device *dev,
+   unsigned op, unsigned opf, gfp_t gfp, struct page *p,
+   bio_end_io_t *end_io)
+{
+   struct bio *bio = bio_new(dev, swap_page_sector(p), op, opf, 1, gfp);
+
+   bio->bi_end_io = end_io;
+   bio_add_page(bio, p, thp_size(p), 0);
+   return bio;
+}
+
 int __swap_writepage(struct page *page, struct writeback_control *wbc,
bio_end_io_t end_write_func)
 {
@@ -342,11 +353,9 @@ int __swap_writepage(struct page *page, struct 
writeback_control *wbc,
return 0;
}
 
-   bio = bio_new(sis->bdev, swap_page_sector(page), REQ_OP_WRITE,
-   REQ_SWAP | wbc_to_write_flags(wbc), 1, GFP_NOIO);
-   bio->bi_end_io = end_write_func;
-   bio_add_page(bio, page, thp_size(page), 0);
-
+   bio = swap_bio_new(sis->bdev, REQ_OP_WRITE,
+   REQ_SWAP | wbc_to_write_flags(wbc), GFP_KERNEL,
+   page, end_write_func);
bio_associate_blkg_from_page(bio, page);
count_swpout_vm_event(page);
set_page_writeback(page);
@@ -406,11 +415,8 @@ int swap_readpage(struct page *page, bool synchronous)
}
 
ret = 0;
-   bio = bio_new(sis->bdev, swap_page_sector(page), REQ_OP_READ, 0, 1,
-   GFP_KERNEL);
-   bio->bi_end_io = end_swap_bio_read;
-   bio_add_page(bio, page, thp_size(page), 0);
-
+   bio = swap_bio_new(sis->bdev, REQ_OP_READ, 0, GFP_KERNEL, page,
+   end_swap_bio_read);
disk = bio->bi_bdev->bd_disk;
/*
 * Keep this task valid during swap readpage because the oom killer may
-- 
2.22.1



[PATCH] blk-cgroup: Remove obsolete macro

2021-01-27 Thread Baolin Wang
Remove the obsolete 'MAX_KEY_LEN' macro.

Signed-off-by: Baolin Wang 
---
 block/blk-cgroup.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 4b4fcb5..a317c03 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -32,8 +32,6 @@
 #include 
 #include "blk.h"
 
-#define MAX_KEY_LEN 100
-
 /*
  * blkcg_pol_mutex protects blkcg_policy[] and policy [de]activation.
  * blkcg_pol_register_mutex nests outside of it and synchronizes entire
-- 
1.8.3.1



[RFC PATCH 33/34] mm: use bio_new in swap_readpage

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 mm/page_io.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index 25b321489703..7579485ccb5e 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -342,7 +342,7 @@ int __swap_writepage(struct page *page, struct 
writeback_control *wbc,
return 0;
}
 
-   bio = bio_alloc(sis->bdev, swap_page_sector(page), REQ_OP_WRITE,
+   bio = bio_new(sis->bdev, swap_page_sector(page), REQ_OP_WRITE,
REQ_SWAP | wbc_to_write_flags(wbc), 1, GFP_NOIO);
bio->bi_end_io = end_write_func;
bio_add_page(bio, page, thp_size(page), 0);
@@ -406,10 +406,8 @@ int swap_readpage(struct page *page, bool synchronous)
}
 
ret = 0;
-   bio = bio_alloc(GFP_KERNEL, 1);
-   bio_set_dev(bio, sis->bdev);
-   bio->bi_opf = REQ_OP_READ;
-   bio->bi_iter.bi_sector = swap_page_sector(page);
+   bio = bio_new(sis->bdev, swap_page_sector(page), REQ_OP_READ, 0, 1,
+   GFP_KERNEL);
bio->bi_end_io = end_swap_bio_read;
bio_add_page(bio, page, thp_size(page), 0);
 
-- 
2.22.1



[RFC PATCH 31/34] iomap: use bio_new in iomap_readpage_actor

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/iomap/buffered-io.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 16a1e82e3aeb..08d119b62cf5 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -241,6 +241,9 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, 
loff_t length, void *data,
struct page *page = ctx->cur_page;
struct iomap_page *iop = iomap_page_create(inode, page);
bool same_page = false, is_contig = false;
+   struct block_device *bdev = iomap->bdev;
+   unsigned opf = ctx->rac ? REQ_RAHEAD : 0;
+   unsigned op = REQ_OP_READ;
loff_t orig_pos = pos;
unsigned poff, plen;
sector_t sector;
@@ -285,19 +288,14 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, 
loff_t length, void *data,
 
if (ctx->rac) /* same as readahead_gfp_mask */
gfp |= __GFP_NORETRY | __GFP_NOWARN;
-   ctx->bio = bio_alloc(gfp, min(BIO_MAX_PAGES, nr_vecs));
+   ctx->bio = bio_new(bdev, sector, op, opf, gfp, nr_vecs);
/*
 * If the bio_alloc fails, try it again for a single page to
 * avoid having to deal with partial page reads.  This emulates
 * what do_mpage_readpage does.
 */
if (!ctx->bio)
-   ctx->bio = bio_alloc(orig_gfp, 1);
-   ctx->bio->bi_opf = REQ_OP_READ;
-   if (ctx->rac)
-   ctx->bio->bi_opf |= REQ_RAHEAD;
-   ctx->bio->bi_iter.bi_sector = sector;
-   bio_set_dev(ctx->bio, iomap->bdev);
+   ctx->bio = bio_new(bdev, sector, op, opf, orig_gfp, 1);
ctx->bio->bi_end_io = iomap_read_end_io;
}
 
-- 
2.22.1



[RFC PATCH 29/34] power/swap: use bio_new in hib_submit_io

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 kernel/power/swap.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index c73f2e295167..e92e36c053a6 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -271,13 +271,12 @@ static int hib_submit_io(int op, int op_flags, pgoff_t 
page_off, void *addr,
struct hib_bio_batch *hb)
 {
struct page *page = virt_to_page(addr);
+   sector_t sect = page_off * (PAGE_SIZE >> 9);
struct bio *bio;
int error = 0;
 
-   bio = bio_alloc(GFP_NOIO | __GFP_HIGH, 1);
-   bio->bi_iter.bi_sector = page_off * (PAGE_SIZE >> 9);
-   bio_set_dev(bio, hib_resume_bdev);
-   bio_set_op_attrs(bio, op, op_flags);
+   bio = bio_new(hib_resume_bdev, sect, op, op_flags, 1,
+ GFP_NOIO | __GFP_HIGH);
 
if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
pr_err("Adding page to bio failed at %llu\n",
-- 
2.22.1



[RFC PATCH 25/34] ocfs/cluster: use bio_new in dm-log-writes

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/ocfs2/cluster/heartbeat.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 0179a73a3fa2..b34518036446 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -515,12 +515,13 @@ static struct bio *o2hb_setup_one_bio(struct o2hb_region 
*reg,
unsigned int cs = *current_slot;
struct bio *bio;
struct page *page;
+   sector_t sect = (reg->hr_start_block + cs) << (bits - 9);
 
/* Testing has shown this allocation to take long enough under
 * GFP_KERNEL that the local node can get fenced. It would be
 * nicest if we could pre-allocate these bios and avoid this
 * all together. */
-   bio = bio_alloc(GFP_ATOMIC, 16);
+   bio = bio_new(reg->hr_bdev, sect, op, op_flags, 16, GFP_ATOMIC);
if (!bio) {
mlog(ML_ERROR, "Could not alloc slots BIO!\n");
bio = ERR_PTR(-ENOMEM);
@@ -528,11 +529,8 @@ static struct bio *o2hb_setup_one_bio(struct o2hb_region 
*reg,
}
 
/* Must put everything in 512 byte sectors for the bio... */
-   bio->bi_iter.bi_sector = (reg->hr_start_block + cs) << (bits - 9);
-   bio_set_dev(bio, reg->hr_bdev);
bio->bi_private = wc;
bio->bi_end_io = o2hb_bio_end_io;
-   bio_set_op_attrs(bio, op, op_flags);
 
vec_start = (cs << bits) % PAGE_SIZE;
while(cs < max_slots) {
-- 
2.22.1



Re: [RESEND PATCH 1/2] KVM: X86: Add support for the emulation of DR6_BUS_LOCK bit

2021-01-27 Thread Xiaoyao Li

On 1/27/2021 6:04 PM, Paolo Bonzini wrote:

On 27/01/21 04:41, Xiaoyao Li wrote:

On 1/27/2021 12:31 AM, Paolo Bonzini wrote:

On 08/01/21 07:49, Chenyi Qiang wrote:

To avoid breaking the CPUs without bus lock detection, activate the
DR6_BUS_LOCK bit (bit 11) conditionally in DR6_FIXED_1 bits.

The set/clear of DR6_BUS_LOCK is similar to the DR6_RTM in DR6
register. The processor clears DR6_BUS_LOCK when bus lock debug
exception is generated. (For all other #DB the processor sets this bit
to 1.) Software #DB handler should set this bit before returning to the
interrupted task.

For VM exit caused by debug exception, bit 11 of the exit qualification
is set to indicate that a bus lock debug exception condition was
detected. The VMM should emulate the exception by clearing bit 11 of 
the

guest DR6.


Please rename DR6_INIT to DR6_ACTIVE_LOW, and then a lot of changes 
become simpler:


Paolo,

What do you want to convey with the new name DR6_ACTIVE_LOW? To be 
honest, the new name is confusing to me.


"Active low" means that the bit is usually 1 and goes to 0 when the 
condition (such as RTM or bus lock) happens.  For almost all those DR6 
bits the value is in fact always 1, but if they are defined in the 
future it will require no code change.


Why not keep use DR6_INIT, or DR6_RESET_VALUE? or any other better name.

It's just the default clear value of DR6 that no debug condition is hit.


Paolo


-    dr6 |= DR6_BD | DR6_RTM;
+    dr6 |= DR6_BD | DR6_RTM | DR6_BUS_LOCK;


dr6 |= DR6_BD | DR6_ACTIVE_LOW;










[RFC PATCH 28/34] zonefs: use bio_new

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/zonefs/super.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
index ab68e27bb322..620d67965a22 100644
--- a/fs/zonefs/super.c
+++ b/fs/zonefs/super.c
@@ -661,6 +661,7 @@ static const struct iomap_dio_ops zonefs_write_dio_ops = {
 
 static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter 
*from)
 {
+   unsigned int op = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE;
struct inode *inode = file_inode(iocb->ki_filp);
struct zonefs_inode_info *zi = ZONEFS_I(inode);
struct block_device *bdev = inode->i_sb->s_bdev;
@@ -678,15 +679,12 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, 
struct iov_iter *from)
if (!nr_pages)
return 0;
 
-   bio = bio_alloc(GFP_NOFS, nr_pages);
+   bio = bio_new(bdev, zi->i_zsector, op, 0, GFP_NOFS, nr_pages);
if (!bio)
return -ENOMEM;
 
-   bio_set_dev(bio, bdev);
-   bio->bi_iter.bi_sector = zi->i_zsector;
bio->bi_write_hint = iocb->ki_hint;
bio->bi_ioprio = iocb->ki_ioprio;
-   bio->bi_opf = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE;
if (iocb->ki_flags & IOCB_DSYNC)
bio->bi_opf |= REQ_FUA;
 
-- 
2.22.1



[RFC PATCH 22/34] fs/jfs/jfs_metapage.c: use bio_new in metapage_readpage

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/jfs/jfs_metapage.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c
index 3fa09d9a0b94..c7be3a2773bf 100644
--- a/fs/jfs/jfs_metapage.c
+++ b/fs/jfs/jfs_metapage.c
@@ -495,13 +495,11 @@ static int metapage_readpage(struct file *fp, struct page 
*page)
if (bio)
submit_bio(bio);
 
-   bio = bio_alloc(GFP_NOFS, 1);
-   bio_set_dev(bio, inode->i_sb->s_bdev);
-   bio->bi_iter.bi_sector =
-   pblock << (inode->i_blkbits - 9);
+   bio = bio_new(inode->i_sb->s_bdev,
+   pblock << (inode->i_blkbits - 9),
+   REQ_OP_READ, 0, 1, GFP_NOFS);
bio->bi_end_io = metapage_read_end_io;
bio->bi_private = page;
-   bio_set_op_attrs(bio, REQ_OP_READ, 0);
len = xlen << inode->i_blkbits;
offset = block_offset << inode->i_blkbits;
if (bio_add_page(bio, page, len, offset) < len)
-- 
2.22.1



[RFC PATCH 15/34] fscrypt: use bio_new in fscrypt_zeroout_range

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/crypto/bio.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/crypto/bio.c b/fs/crypto/bio.c
index b048a0e38516..20dab9bdf098 100644
--- a/fs/crypto/bio.c
+++ b/fs/crypto/bio.c
@@ -148,12 +148,11 @@ int fscrypt_zeroout_range(const struct inode *inode, 
pgoff_t lblk,
return -EINVAL;
 
/* This always succeeds since __GFP_DIRECT_RECLAIM is set. */
-   bio = bio_alloc(GFP_NOFS, nr_pages);
+   bio = bio_alloc(inode->i_sb->s_bdev, 0, REQ_OP_WRITE, 0, nr_pages,
+   GFP_NOFS);
 
do {
-   bio_set_dev(bio, inode->i_sb->s_bdev);
bio->bi_iter.bi_sector = pblk << (blockbits - 9);
-   bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
 
i = 0;
offset = 0;
-- 
2.22.1



[RFC PATCH 20/34] fs/jfs/jfs_logmgr.c: use bio_new in lbmStartIO

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/jfs/jfs_logmgr.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index 4481f3e33a3f..bb25737d52f6 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -2121,16 +2121,14 @@ static void lbmStartIO(struct lbuf * bp)
 
jfs_info("lbmStartIO");
 
-   bio = bio_alloc(GFP_NOFS, 1);
-   bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize - 9);
-   bio_set_dev(bio, log->bdev);
+   bio = bio_new(log->bdev, bp->l_blkno << (log->l2bsize - 9),
+   REQ_OP_WRITE | REQ_SYNC, 0, 1, GFP_NOFS);
 
bio_add_page(bio, bp->l_page, LOGPSIZE, bp->l_offset);
BUG_ON(bio->bi_iter.bi_size != LOGPSIZE);
 
bio->bi_end_io = lbmIODone;
bio->bi_private = bp;
-   bio->bi_opf = REQ_OP_WRITE | REQ_SYNC;
 
/* check if journaling to disk has been disabled */
if (log->no_integrity) {
-- 
2.22.1



[RFC PATCH 12/34] scsi: target/iblock: use bio_new

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/target/target_core_iblock.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/target/target_core_iblock.c 
b/drivers/target/target_core_iblock.c
index 8ed93fd205c7..f1264918aee1 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -379,10 +379,9 @@ iblock_execute_sync_cache(struct se_cmd *cmd)
if (immed)
target_complete_cmd(cmd, SAM_STAT_GOOD);
 
-   bio = bio_alloc(GFP_KERNEL, 0);
+   bio = bio_new(ib_dev->ibd_bd, 0, REQ_OP_WRITE, REQ_PREFLUSH, 0,
+ GFP_KERNEL);
bio->bi_end_io = iblock_end_io_flush;
-   bio_set_dev(bio, ib_dev->ibd_bd);
-   bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
if (!immed)
bio->bi_private = cmd;
submit_bio(bio);
-- 
2.22.1



[RFC PATCH 13/34] block: use bio_new in __blkdev_direct_IO

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/block_dev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 9d4b1a884d76..f3e3247894d7 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -367,6 +367,8 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter 
*iter, int nr_pages)
return -EINVAL;
 
bio = bio_alloc_bioset(GFP_KERNEL, nr_pages, _dio_pool);
+   bio_set_dev(bio, bdev);
+   bio->bi_iter.bi_sector = pos >> 9;
 
dio = container_of(bio, struct blkdev_dio, bio);
dio->is_sync = is_sync = is_sync_kiocb(iocb);
@@ -389,8 +391,6 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter 
*iter, int nr_pages)
blk_start_plug();
 
for (;;) {
-   bio_set_dev(bio, bdev);
-   bio->bi_iter.bi_sector = pos >> 9;
bio->bi_write_hint = iocb->ki_hint;
bio->bi_private = dio;
bio->bi_end_io = blkdev_bio_end_io;
@@ -446,7 +446,7 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter 
*iter, int nr_pages)
}
 
submit_bio(bio);
-   bio = bio_alloc(GFP_KERNEL, nr_pages);
+   bio = bio_new(bdev, pos >> 9, 0, 0, nr_pages, GFP_KERNEL);
}
 
if (!is_poll)
-- 
2.22.1



[RFC PATCH 08/34] dm-zoned: use bio_new in get_mblock_slow

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/md/dm-zoned-metadata.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
index 039d17b28938..e6252f48a49c 100644
--- a/drivers/md/dm-zoned-metadata.c
+++ b/drivers/md/dm-zoned-metadata.c
@@ -550,7 +550,8 @@ static struct dmz_mblock *dmz_get_mblock_slow(struct 
dmz_metadata *zmd,
if (!mblk)
return ERR_PTR(-ENOMEM);
 
-   bio = bio_alloc(GFP_NOIO, 1);
+   bio = bio_new(dev->bdev, dmz_blk2sect(block), REQ_OP_READ,
+ REQ_META | REQ_PRIO, 1, GFP_NOIO);
if (!bio) {
dmz_free_mblock(zmd, mblk);
return ERR_PTR(-ENOMEM);
@@ -577,11 +578,8 @@ static struct dmz_mblock *dmz_get_mblock_slow(struct 
dmz_metadata *zmd,
spin_unlock(>mblk_lock);
 
/* Submit read BIO */
-   bio->bi_iter.bi_sector = dmz_blk2sect(block);
-   bio_set_dev(bio, dev->bdev);
bio->bi_private = mblk;
bio->bi_end_io = dmz_mblock_bio_end_io;
-   bio_set_op_attrs(bio, REQ_OP_READ, REQ_META | REQ_PRIO);
bio_add_page(bio, mblk->page, DMZ_BLOCK_SIZE, 0);
submit_bio(bio);
 
-- 
2.22.1



[RFC PATCH 09/34] dm-zoned: use bio_new in dmz_write_mblock

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/md/dm-zoned-metadata.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
index e6252f48a49c..fa0ee732c6e9 100644
--- a/drivers/md/dm-zoned-metadata.c
+++ b/drivers/md/dm-zoned-metadata.c
@@ -723,7 +723,8 @@ static int dmz_write_mblock(struct dmz_metadata *zmd, 
struct dmz_mblock *mblk,
if (dmz_bdev_is_dying(dev))
return -EIO;
 
-   bio = bio_alloc(GFP_NOIO, 1);
+   bio = bio_new(dev->bdev, dmz_blk2sect(block), REQ_OP_WRITE,
+ REQ_META | REQ_PRIO, 1, GFP_NOIO);
if (!bio) {
set_bit(DMZ_META_ERROR, >state);
return -ENOMEM;
@@ -731,11 +732,8 @@ static int dmz_write_mblock(struct dmz_metadata *zmd, 
struct dmz_mblock *mblk,
 
set_bit(DMZ_META_WRITING, >state);
 
-   bio->bi_iter.bi_sector = dmz_blk2sect(block);
-   bio_set_dev(bio, dev->bdev);
bio->bi_private = mblk;
bio->bi_end_io = dmz_mblock_bio_end_io;
-   bio_set_op_attrs(bio, REQ_OP_WRITE, REQ_META | REQ_PRIO);
bio_add_page(bio, mblk->page, DMZ_BLOCK_SIZE, 0);
submit_bio(bio);
 
-- 
2.22.1



[RFC PATCH 03/34] drdb: use bio_new in drdb

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/block/drbd/drbd_receiver.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/block/drbd/drbd_receiver.c 
b/drivers/block/drbd/drbd_receiver.c
index 09c86ef3f0fd..e1cd3427b28b 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -1643,6 +1643,7 @@ int drbd_submit_peer_request(struct drbd_device *device,
struct bio *bio;
struct page *page = peer_req->pages;
sector_t sector = peer_req->i.sector;
+   struct block_device *bdev = device->ldev->backing_bdev;
unsigned data_size = peer_req->i.size;
unsigned n_bios = 0;
unsigned nr_pages = (data_size + PAGE_SIZE -1) >> PAGE_SHIFT;
@@ -1687,15 +1688,12 @@ int drbd_submit_peer_request(struct drbd_device *device,
 * generated bio, but a bio allocated on behalf of the peer.
 */
 next_bio:
-   bio = bio_alloc(GFP_NOIO, nr_pages);
+   bio = bio_new(bdev, sector, op, op_flags, GFP_NOIO, nr_pages);
if (!bio) {
drbd_err(device, "submit_ee: Allocation of a bio failed 
(nr_pages=%u)\n", nr_pages);
goto fail;
}
/* > peer_req->i.sector, unless this is the first bio */
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, device->ldev->backing_bdev);
-   bio_set_op_attrs(bio, op, op_flags);
bio->bi_private = peer_req;
bio->bi_end_io = drbd_peer_request_endio;
 
-- 
2.22.1



[RFC PATCH 04/34] drdb: use bio_new() in submit_one_flush

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/block/drbd/drbd_receiver.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/block/drbd/drbd_receiver.c 
b/drivers/block/drbd/drbd_receiver.c
index e1cd3427b28b..b86bbf725cbd 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -1277,8 +1277,10 @@ static void one_flush_endio(struct bio *bio)
 
 static void submit_one_flush(struct drbd_device *device, struct 
issue_flush_context *ctx)
 {
-   struct bio *bio = bio_alloc(GFP_NOIO, 0);
+   struct block_device *bdev = device->ldev->backing_bdev;
+   struct bio *bio = bio_new(bdev, 0, REQ_OP_FLUSH, REQ_PREFLUSH, 0, 
GFP_NOIO);
struct one_flush_context *octx = kmalloc(sizeof(*octx), GFP_NOIO);
+
if (!bio || !octx) {
drbd_warn(device, "Could not allocate a bio, CANNOT ISSUE 
FLUSH\n");
/* FIXME: what else can I do now?  disconnecting or detaching
@@ -1296,10 +1298,8 @@ static void submit_one_flush(struct drbd_device *device, 
struct issue_flush_cont
 
octx->device = device;
octx->ctx = ctx;
-   bio_set_dev(bio, device->ldev->backing_bdev);
bio->bi_private = octx;
bio->bi_end_io = one_flush_endio;
-   bio->bi_opf = REQ_OP_FLUSH | REQ_PREFLUSH;
 
device->flush_jif = jiffies;
set_bit(FLUSH_PENDING, >flags);
-- 
2.22.1



[PATCH v2 0/3] handle large user and group ID for isofs and udf

2021-01-27 Thread bingjingc
From: BingJing Chang 

The uid/gid (unsigned int) of a domain user may be larger than INT_MAX.
The parse_options of isofs and udf will return 0, and mount will fail
with -EINVAL. These patches try to handle large user and group ID.

BingJing Chang (3):
  parser: add unsigned int parser
  isofs: handle large user and group ID
  udf: handle large user and group ID

 fs/isofs/inode.c   |  9 +
 fs/udf/super.c |  9 +
 include/linux/parser.h |  1 +
 lib/parser.c   | 44 +---
 4 files changed, 44 insertions(+), 19 deletions(-)

-- 
2.7.4



[PATCH v3 17/25] mm/filemap: Convert end_page_writeback to end_folio_writeback

2021-01-27 Thread Matthew Wilcox (Oracle)
Add a wrapper function for users that are not yet converted to folios.
With a distro config, this function shrinks from 213 bytes to 105 bytes
due to elimination of repeated calls to compound_head().

Signed-off-by: Matthew Wilcox (Oracle) 
---
 include/linux/pagemap.h |  6 +-
 mm/filemap.c| 30 +++---
 2 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 131d1aa2af61..67d3badc9fe0 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -758,7 +758,11 @@ static inline void wait_on_page_fscache(struct page *page)
 
 int put_and_wait_on_page_locked(struct page *page, int state);
 void wait_on_page_writeback(struct page *page);
-extern void end_page_writeback(struct page *page);
+void end_folio_writeback(struct folio *folio);
+static inline void end_page_writeback(struct page *page)
+{
+   return end_folio_writeback(page_folio(page));
+}
 void wait_for_stable_page(struct page *page);
 
 void page_endio(struct page *page, bool is_write, int err);
diff --git a/mm/filemap.c b/mm/filemap.c
index a54eb4641385..65008c42e47d 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1147,11 +1147,11 @@ static void wake_up_page_bit(struct page *page, int 
bit_nr)
spin_unlock_irqrestore(>lock, flags);
 }
 
-static void wake_up_page(struct page *page, int bit)
+static void wake_up_folio(struct folio *folio, int bit)
 {
-   if (!PageWaiters(page))
+   if (!FolioWaiters(folio))
return;
-   wake_up_page_bit(page, bit);
+   wake_up_page_bit(>page, bit);
 }
 
 /*
@@ -1443,10 +1443,10 @@ void unlock_page_fscache(struct page *page)
 EXPORT_SYMBOL(unlock_page_fscache);
 
 /**
- * end_page_writeback - end writeback against a page
- * @page: the page
+ * end_folio_writeback - End writeback against a page.
+ * @folio: The page.
  */
-void end_page_writeback(struct page *page)
+void end_folio_writeback(struct folio *folio)
 {
/*
 * TestClearPageReclaim could be used here but it is an atomic
@@ -1455,26 +1455,26 @@ void end_page_writeback(struct page *page)
 * justify taking an atomic operation penalty at the end of
 * ever page writeback.
 */
-   if (PageReclaim(page)) {
-   ClearPageReclaim(page);
-   rotate_reclaimable_page(page);
+   if (FolioReclaim(folio)) {
+   ClearFolioReclaim(folio);
+   rotate_reclaimable_page(>page);
}
 
/*
 * Writeback does not hold a page reference of its own, relying
 * on truncation to wait for the clearing of PG_writeback.
 * But here we must make sure that the page is not freed and
-* reused before the wake_up_page().
+* reused before the wake_up_folio().
 */
-   get_page(page);
-   if (!test_clear_page_writeback(page))
+   get_folio(folio);
+   if (!test_clear_page_writeback(>page))
BUG();
 
smp_mb__after_atomic();
-   wake_up_page(page, PG_writeback);
-   put_page(page);
+   wake_up_folio(folio, PG_writeback);
+   put_folio(folio);
 }
-EXPORT_SYMBOL(end_page_writeback);
+EXPORT_SYMBOL(end_folio_writeback);
 
 /*
  * After completing I/O on a page, call this routine to update the page
-- 
2.29.2



[RFC PATCH 01/34] block: move common code into blk_next_bio()

2021-01-27 Thread Chaitanya Kulkarni
blk_next_bio() is the central function which allocates the bios for
discard, write-same, write-zeroes and zone-mgmt. The initialization of
various bio members is duplicated in disacrd, write-same, write-zeores.
In this preparation patch we add bdev, sector, op, and opf arguments to
the blk_next_bio() to reduce the duplication. 

In the next patch we introduce bio_new(), this prepration patch allows
us to call it inside blk_next_bio().

Signed-off-by: Chaitanya Kulkarni 
---
 block/blk-lib.c   | 36 +++-
 block/blk-zoned.c |  4 +---
 block/blk.h   |  5 +++--
 3 files changed, 19 insertions(+), 26 deletions(-)

diff --git a/block/blk-lib.c b/block/blk-lib.c
index 752f9c722062..fb486a0bdb58 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -10,7 +10,9 @@
 
 #include "blk.h"
 
-struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp)
+struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev,
+   sector_t sect, unsigned op, unsigned opf,
+   unsigned int nr_pages, gfp_t gfp)
 {
struct bio *new = bio_alloc(gfp, nr_pages);
 
@@ -19,6 +21,10 @@ struct bio *blk_next_bio(struct bio *bio, unsigned int 
nr_pages, gfp_t gfp)
submit_bio(bio);
}
 
+   new->bi_iter.bi_sector = sect;
+   bio_set_dev(new, bdev);
+   bio_set_op_attrs(new, op, opf);
+
return new;
 }
 
@@ -94,11 +100,7 @@ int __blkdev_issue_discard(struct block_device *bdev, 
sector_t sector,
 
WARN_ON_ONCE((req_sects << 9) > UINT_MAX);
 
-   bio = blk_next_bio(bio, 0, gfp_mask);
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, bdev);
-   bio_set_op_attrs(bio, op, 0);
-
+   bio = blk_next_bio(bio, bdev, sector, op, 0, 0, gfp_mask);
bio->bi_iter.bi_size = req_sects << 9;
sector += req_sects;
nr_sects -= req_sects;
@@ -168,6 +170,7 @@ static int __blkdev_issue_write_same(struct block_device 
*bdev, sector_t sector,
 {
struct request_queue *q = bdev_get_queue(bdev);
unsigned int max_write_same_sectors;
+   unsigned int op = REQ_OP_WRITE_SAME;
struct bio *bio = *biop;
sector_t bs_mask;
 
@@ -188,14 +191,11 @@ static int __blkdev_issue_write_same(struct block_device 
*bdev, sector_t sector,
max_write_same_sectors = bio_allowed_max_sectors(q);
 
while (nr_sects) {
-   bio = blk_next_bio(bio, 1, gfp_mask);
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, bdev);
+   bio = blk_next_bio(bio, bdev, sector, op, 0, 1, gfp_mask);
bio->bi_vcnt = 1;
bio->bi_io_vec->bv_page = page;
bio->bi_io_vec->bv_offset = 0;
bio->bi_io_vec->bv_len = bdev_logical_block_size(bdev);
-   bio_set_op_attrs(bio, REQ_OP_WRITE_SAME, 0);
 
if (nr_sects > max_write_same_sectors) {
bio->bi_iter.bi_size = max_write_same_sectors << 9;
@@ -249,7 +249,9 @@ static int __blkdev_issue_write_zeroes(struct block_device 
*bdev,
 {
struct bio *bio = *biop;
unsigned int max_write_zeroes_sectors;
+   unsigned int op = REQ_OP_WRITE_ZEROES;
struct request_queue *q = bdev_get_queue(bdev);
+   unsigned int opf = flags & BLKDEV_ZERO_NOUNMAP ? REQ_NOUNMAP : 0;
 
if (!q)
return -ENXIO;
@@ -264,13 +266,7 @@ static int __blkdev_issue_write_zeroes(struct block_device 
*bdev,
return -EOPNOTSUPP;
 
while (nr_sects) {
-   bio = blk_next_bio(bio, 0, gfp_mask);
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, bdev);
-   bio->bi_opf = REQ_OP_WRITE_ZEROES;
-   if (flags & BLKDEV_ZERO_NOUNMAP)
-   bio->bi_opf |= REQ_NOUNMAP;
-
+   bio = blk_next_bio(bio, bdev, sector, op, opf, 0, gfp_mask);
if (nr_sects > max_write_zeroes_sectors) {
bio->bi_iter.bi_size = max_write_zeroes_sectors << 9;
nr_sects -= max_write_zeroes_sectors;
@@ -303,6 +299,7 @@ static int __blkdev_issue_zero_pages(struct block_device 
*bdev,
sector_t sector, sector_t nr_sects, gfp_t gfp_mask,
struct bio **biop)
 {
+   unsigned int nr_pages = __blkdev_sectors_to_bio_pages(nr_sects);
struct request_queue *q = bdev_get_queue(bdev);
struct bio *bio = *biop;
int bi_size = 0;
@@ -315,11 +312,8 @@ static int __blkdev_issue_zero_pages(struct block_device 
*bdev,
return -EPERM;
 
while (nr_sects != 0) {
-   bio = blk_next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects),
+   bio = blk_next_bio(bio, bdev, sector, REQ_OP_WRITE, 0, nr_pages,
   gfp_mask);
-   

[PATCH v3 21/25] mm: Convert lock_page_or_retry to lock_folio_or_retry

2021-01-27 Thread Matthew Wilcox (Oracle)
There's already a hidden compound_head() call in trylock_page(), so
just make it explicit in the caller, which may later have a folio
for its own reasons.  This saves a call to compound_head() inside
__lock_page_or_retry().

Signed-off-by: Matthew Wilcox (Oracle) 
---
 include/linux/pagemap.h | 10 +-
 mm/filemap.c| 16 +++-
 mm/memory.c | 10 +-
 3 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 546565a7907c..f59af1547e7b 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -621,7 +621,7 @@ static inline bool wake_page_match(struct wait_page_queue 
*wait_page,
 void __lock_folio(struct folio *folio);
 int __lock_folio_killable(struct folio *folio);
 int __lock_folio_async(struct folio *folio, struct wait_page_queue *wait);
-extern int __lock_page_or_retry(struct page *page, struct mm_struct *mm,
+int __lock_folio_or_retry(struct folio *folio, struct mm_struct *mm,
unsigned int flags);
 void unlock_folio(struct folio *folio);
 extern void unlock_page_fscache(struct page *page);
@@ -703,17 +703,17 @@ static inline int lock_folio_async(struct folio *folio,
 }
 
 /*
- * lock_page_or_retry - Lock the page, unless this would block and the
+ * lock_folio_or_retry - Lock the folio, unless this would block and the
  * caller indicated that it can handle a retry.
  *
  * Return value and mmap_lock implications depend on flags; see
- * __lock_page_or_retry().
+ * __lock_folio_or_retry().
  */
-static inline int lock_page_or_retry(struct page *page, struct mm_struct *mm,
+static inline int lock_folio_or_retry(struct folio *folio, struct mm_struct 
*mm,
 unsigned int flags)
 {
might_sleep();
-   return trylock_page(page) || __lock_page_or_retry(page, mm, flags);
+   return trylock_folio(folio) || __lock_folio_or_retry(folio, mm, flags);
 }
 
 /*
diff --git a/mm/filemap.c b/mm/filemap.c
index f68bf0129458..f0a76258de97 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1546,20 +1546,18 @@ int __lock_folio_async(struct folio *folio, struct 
wait_page_queue *wait)
 
 /*
  * Return values:
- * 1 - page is locked; mmap_lock is still held.
- * 0 - page is not locked.
+ * 1 - folio is locked; mmap_lock is still held.
+ * 0 - folio is not locked.
  * mmap_lock has been released (mmap_read_unlock(), unless flags had both
  * FAULT_FLAG_ALLOW_RETRY and FAULT_FLAG_RETRY_NOWAIT set, in
  * which case mmap_lock is still held.
  *
  * If neither ALLOW_RETRY nor KILLABLE are set, will always return 1
- * with the page locked and the mmap_lock unperturbed.
+ * with the folio locked and the mmap_lock unperturbed.
  */
-int __lock_page_or_retry(struct page *page, struct mm_struct *mm,
+int __lock_folio_or_retry(struct folio *folio, struct mm_struct *mm,
 unsigned int flags)
 {
-   struct folio *folio = page_folio(page);
-
if (fault_flag_allow_retry_first(flags)) {
/*
 * CAUTION! In this case, mmap_lock is not released
@@ -1570,9 +1568,9 @@ int __lock_page_or_retry(struct page *page, struct 
mm_struct *mm,
 
mmap_read_unlock(mm);
if (flags & FAULT_FLAG_KILLABLE)
-   wait_on_page_locked_killable(page);
+   wait_on_folio_locked_killable(folio);
else
-   wait_on_page_locked(page);
+   wait_on_folio_locked(folio);
return 0;
}
if (flags & FAULT_FLAG_KILLABLE) {
@@ -2724,7 +2722,7 @@ loff_t mapping_seek_hole_data(struct address_space 
*mapping, loff_t start,
  * @page - the page to lock.
  * @fpin - the pointer to the file we may pin (or is already pinned).
  *
- * This works similar to lock_page_or_retry in that it can drop the mmap_lock.
+ * This works similar to lock_folio_or_retry in that it can drop the mmap_lock.
  * It differs in that it actually returns the page locked if it returns 1 and 0
  * if it couldn't lock the page.  If we did have to drop the mmap_lock then 
fpin
  * will point to the pinned file and needs to be fput()'ed at a later point.
diff --git a/mm/memory.c b/mm/memory.c
index 06992770f23e..bb15abef559b 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3352,7 +3352,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
goto out_release;
}
 
-   locked = lock_page_or_retry(page, vma->vm_mm, vmf->flags);
+   locked = lock_folio_or_retry(page_folio(page), vma->vm_mm, vmf->flags);
 
delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
if (!locked) {
@@ -4104,7 +4104,7 @@ static vm_fault_t do_shared_fault(struct vm_fault *vmf)
  * We enter with non-exclusive mmap_lock (to exclude vma changes,
  * but allow concurrent faults).
  * The mmap_lock may have been released depending on flags and our
- * return value.  See filemap_fault() and 

[PATCH] media/pci: fix spelling typo of frimware

2021-01-27 Thread dingsenjie
From: dingsenjie 

frimware -> firmware

Signed-off-by: dingsenjie 
---
 drivers/media/pci/saa7164/saa7164.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/saa7164/saa7164.h 
b/drivers/media/pci/saa7164/saa7164.h
index 2801a2b..4b4eb15 100644
--- a/drivers/media/pci/saa7164/saa7164.h
+++ b/drivers/media/pci/saa7164/saa7164.h
@@ -24,7 +24,7 @@
saa7164_bus..() : Manage a read/write memory ring buffer in the
|   : PCIe Address space.
|
-   |   saa7164_fw...() : Load any frimware
+   |   saa7164_fw...() : Load any firmware
|   |   : direct into the device
V   V
<- - PCIe address space  ->
-- 
1.9.1




[PATCH v3 19/25] mm: Add wait_for_stable_folio and wait_on_folio_writeback

2021-01-27 Thread Matthew Wilcox (Oracle)
Add compatibility wrappers for code which has not yet been converted
to use folios.

Signed-off-by: Matthew Wilcox (Oracle) 
---
 include/linux/pagemap.h | 12 ++--
 mm/page-writeback.c | 27 +--
 2 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 55f3c1a8be3c..757e437e7f09 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -760,13 +760,21 @@ static inline void wait_on_page_fscache(struct page *page)
 }
 
 int put_and_wait_on_page_locked(struct page *page, int state);
-void wait_on_page_writeback(struct page *page);
+void wait_on_folio_writeback(struct folio *folio);
+static inline void wait_on_page_writeback(struct page *page)
+{
+   return wait_on_folio_writeback(page_folio(page));
+}
 void end_folio_writeback(struct folio *folio);
 static inline void end_page_writeback(struct page *page)
 {
return end_folio_writeback(page_folio(page));
 }
-void wait_for_stable_page(struct page *page);
+void wait_for_stable_folio(struct folio *folio);
+static inline void wait_for_stable_page(struct page *page)
+{
+   return wait_for_stable_folio(page_folio(page));
+}
 
 void page_endio(struct page *page, bool is_write, int err);
 
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 51b4326f0aaa..908fc7f60ae7 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2822,30 +2822,29 @@ int __test_set_page_writeback(struct page *page, bool 
keep_write)
 EXPORT_SYMBOL(__test_set_page_writeback);
 
 /*
- * Wait for a page to complete writeback
+ * Wait for a folio to complete writeback
  */
-void wait_on_page_writeback(struct page *page)
+void wait_on_folio_writeback(struct folio *folio)
 {
-   struct folio *folio = page_folio(page);
while (FolioWriteback(folio)) {
-   trace_wait_on_page_writeback(page, folio_mapping(folio));
+   trace_wait_on_page_writeback(>page,
+   folio_mapping(folio));
wait_on_folio_bit(folio, PG_writeback);
}
 }
-EXPORT_SYMBOL_GPL(wait_on_page_writeback);
+EXPORT_SYMBOL_GPL(wait_on_folio_writeback);
 
 /**
- * wait_for_stable_page() - wait for writeback to finish, if necessary.
- * @page:  The page to wait on.
+ * wait_for_stable_folio() - wait for writeback to finish, if necessary.
+ * @folio: The folio to wait on.
  *
- * This function determines if the given page is related to a backing device
- * that requires page contents to be held stable during writeback.  If so, then
+ * This function determines if the given folio is related to a backing device
+ * that requires folio contents to be held stable during writeback.  If so, 
then
  * it will wait for any pending writeback to complete.
  */
-void wait_for_stable_page(struct page *page)
+void wait_for_stable_folio(struct folio *folio)
 {
-   page = thp_head(page);
-   if (page->mapping->host->i_sb->s_iflags & SB_I_STABLE_WRITES)
-   wait_on_page_writeback(page);
+   if (folio->page.mapping->host->i_sb->s_iflags & SB_I_STABLE_WRITES)
+   wait_on_folio_writeback(folio);
 }
-EXPORT_SYMBOL_GPL(wait_for_stable_page);
+EXPORT_SYMBOL_GPL(wait_for_stable_folio);
-- 
2.29.2



[PATCH v3 23/25] mm: Convert test_clear_page_writeback to test_clear_folio_writeback

2021-01-27 Thread Matthew Wilcox (Oracle)
The one caller of test_clear_page_writeback() already has a folio, so make
it clear that test_clear_page_writeback() operates on the entire folio.

Signed-off-by: Matthew Wilcox (Oracle) 
---
 include/linux/page-flags.h |  2 +-
 mm/filemap.c   |  2 +-
 mm/page-writeback.c| 18 +-
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index 90381858d901..01aa4a71bf14 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -594,7 +594,7 @@ static __always_inline void SetPageUptodate(struct page 
*page)
 
 CLEARPAGEFLAG(Uptodate, uptodate, PF_NO_TAIL)
 
-int test_clear_page_writeback(struct page *page);
+int test_clear_folio_writeback(struct folio *folio);
 int __test_set_page_writeback(struct page *page, bool keep_write);
 
 #define test_set_page_writeback(page)  \
diff --git a/mm/filemap.c b/mm/filemap.c
index 906b29c3e1fb..a00030b2ef71 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1463,7 +1463,7 @@ void end_folio_writeback(struct folio *folio)
 * reused before the wake_up_folio().
 */
get_folio(folio);
-   if (!test_clear_page_writeback(>page))
+   if (!test_clear_folio_writeback(folio))
BUG();
 
smp_mb__after_atomic();
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 908fc7f60ae7..db8a99e4a3d2 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2719,24 +2719,24 @@ int clear_page_dirty_for_io(struct page *page)
 }
 EXPORT_SYMBOL(clear_page_dirty_for_io);
 
-int test_clear_page_writeback(struct page *page)
+int test_clear_folio_writeback(struct folio *folio)
 {
-   struct address_space *mapping = page_mapping(page);
+   struct address_space *mapping = folio_mapping(folio);
struct mem_cgroup *memcg;
struct lruvec *lruvec;
int ret;
 
-   memcg = lock_page_memcg(page);
-   lruvec = mem_cgroup_page_lruvec(page, page_pgdat(page));
+   memcg = lock_folio_memcg(folio);
+   lruvec = mem_cgroup_folio_lruvec(folio, folio_pgdat(folio));
if (mapping && mapping_use_writeback_tags(mapping)) {
struct inode *inode = mapping->host;
struct backing_dev_info *bdi = inode_to_bdi(inode);
unsigned long flags;
 
xa_lock_irqsave(>i_pages, flags);
-   ret = TestClearPageWriteback(page);
+   ret = TestClearFolioWriteback(folio);
if (ret) {
-   __xa_clear_mark(>i_pages, page_index(page),
+   __xa_clear_mark(>i_pages, folio_index(folio),
PAGECACHE_TAG_WRITEBACK);
if (bdi->capabilities & BDI_CAP_WRITEBACK_ACCT) {
struct bdi_writeback *wb = inode_to_wb(inode);
@@ -2752,12 +2752,12 @@ int test_clear_page_writeback(struct page *page)
 
xa_unlock_irqrestore(>i_pages, flags);
} else {
-   ret = TestClearPageWriteback(page);
+   ret = TestClearFolioWriteback(folio);
}
if (ret) {
dec_lruvec_state(lruvec, NR_WRITEBACK);
-   dec_zone_page_state(page, NR_ZONE_WRITE_PENDING);
-   inc_node_page_state(page, NR_WRITTEN);
+   dec_zone_folio_stat(folio, NR_ZONE_WRITE_PENDING);
+   inc_node_folio_stat(folio, NR_WRITTEN);
}
__unlock_page_memcg(memcg);
return ret;
-- 
2.29.2



[PATCH v3 25/25] cachefiles: Switch to wait_page_key

2021-01-27 Thread Matthew Wilcox (Oracle)
Cachefiles was relying on wait_page_key and wait_bit_key being the
same layout, which is fragile.  Now that wait_page_key is exposed in
the pagemap.h header, we can remove that fragility.  Also switch it
to use the folio directly instead of the page.

Signed-off-by: Matthew Wilcox (Oracle) 
---
 fs/cachefiles/rdwr.c| 13 ++---
 include/linux/pagemap.h |  1 -
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
index e027c718ca01..b1dbc484a9c7 100644
--- a/fs/cachefiles/rdwr.c
+++ b/fs/cachefiles/rdwr.c
@@ -24,22 +24,21 @@ static int cachefiles_read_waiter(wait_queue_entry_t *wait, 
unsigned mode,
container_of(wait, struct cachefiles_one_read, monitor);
struct cachefiles_object *object;
struct fscache_retrieval *op = monitor->op;
-   struct wait_bit_key *key = _key;
-   struct page *page = wait->private;
+   struct wait_page_key *key = _key;
+   struct folio *folio = wait->private;
 
ASSERT(key);
 
_enter("{%lu},%u,%d,{%p,%u}",
   monitor->netfs_page->index, mode, sync,
-  key->flags, key->bit_nr);
+  key->folio, key->bit_nr);
 
-   if (key->flags != >flags ||
-   key->bit_nr != PG_locked)
+   if (key->folio != folio || key->bit_nr != PG_locked)
return 0;
 
-   _debug("--- monitor %p %lx ---", page, page->flags);
+   _debug("--- monitor %p %lx ---", folio, folio->page.flags);
 
-   if (!PageUptodate(page) && !PageError(page)) {
+   if (!FolioUptodate(folio) && !FolioError(folio)) {
/* unlocked, not uptodate and not erronous? */
_debug("page probably truncated");
}
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index f0a601f6d68c..e8d8c66b027e 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -592,7 +592,6 @@ static inline pgoff_t linear_page_index(struct 
vm_area_struct *vma,
return pgoff;
 }
 
-/* This has the same layout as wait_bit_key - see fs/cachefiles/rdwr.c */
 struct wait_page_key {
struct folio *folio;
int bit_nr;
-- 
2.29.2



Re: [PATCH v18 01/10] fs/ntfs3: Add headers and misc files

2021-01-27 Thread Kari Argillander
On Fri, Jan 22, 2021 at 02:55:30PM +, Mark Harmstone wrote:
> On 22/1/21 2:01 pm, Konstantin Komarov wrote:
> > diff --git a/fs/ntfs3/upcase.c b/fs/ntfs3/upcase.c

> > +static inline u16 upcase_unicode_char(const u16 *upcase, u16 chr)
> > +{
> > +   if (chr < 'a')
> > +   return chr;
> > +
> > +   if (chr <= 'z')
> > +   return chr - ('a' - 'A');
> > +
> > +   return upcase[chr];
> > +}
> 
> Shouldn't upcase_unicode_char be using the NTFS pseudo-file $UpCase?
> That way you should also be covered for other bicameral alphabets.

return upcase[chr] is just for that? Upcase table from $UpCase is constucted
in super.c and this will get it in and use it.


[PATCH v3 14/25] mm: Add lock_folio

2021-01-27 Thread Matthew Wilcox (Oracle)
This is like lock_page() but for use by callers who know they have a folio.
Convert __lock_page() to be __lock_folio().  This saves one call to
compound_head() per contended call to lock_page().

Signed-off-by: Matthew Wilcox (Oracle) 
---
 include/linux/pagemap.h | 21 +++--
 mm/filemap.c| 29 +++--
 2 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 5fcab5e1787c..0e9ad46e8d55 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -618,7 +618,7 @@ static inline bool wake_page_match(struct wait_page_queue 
*wait_page,
return true;
 }
 
-extern void __lock_page(struct page *page);
+void __lock_folio(struct folio *folio);
 extern int __lock_page_killable(struct page *page);
 extern int __lock_page_async(struct page *page, struct wait_page_queue *wait);
 extern int __lock_page_or_retry(struct page *page, struct mm_struct *mm,
@@ -640,13 +640,24 @@ static inline void unlock_page(struct page *page)
return unlock_folio(page_folio(page));
 }
 
+static inline bool trylock_folio(struct folio *folio)
+{
+   return likely(!test_and_set_bit_lock(PG_locked, folio_flags(folio)));
+}
+
 /*
  * Return true if the page was successfully locked
  */
 static inline int trylock_page(struct page *page)
 {
-   page = compound_head(page);
-   return (likely(!test_and_set_bit_lock(PG_locked, >flags)));
+   return trylock_folio(page_folio(page));
+}
+
+static inline void lock_folio(struct folio *folio)
+{
+   might_sleep();
+   if (!trylock_folio(folio))
+   __lock_folio(folio);
 }
 
 /*
@@ -654,9 +665,7 @@ static inline int trylock_page(struct page *page)
  */
 static inline void lock_page(struct page *page)
 {
-   might_sleep();
-   if (!trylock_page(page))
-   __lock_page(page);
+   lock_folio(page_folio(page));
 }
 
 /*
diff --git a/mm/filemap.c b/mm/filemap.c
index b639651d1573..f95967ef16da 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1159,7 +1159,7 @@ static void wake_up_page(struct page *page, int bit)
  */
 enum behavior {
EXCLUSIVE,  /* Hold ref to page and take the bit when woken, like
-* __lock_page() waiting on then setting PG_locked.
+* __lock_folio() waiting on then setting PG_locked.
 */
SHARED, /* Hold ref to page and check the bit when woken, like
 * wait_on_page_writeback() waiting on PG_writeback.
@@ -1505,17 +1505,16 @@ void page_endio(struct page *page, bool is_write, int 
err)
 EXPORT_SYMBOL_GPL(page_endio);
 
 /**
- * __lock_page - get a lock on the page, assuming we need to sleep to get it
- * @__page: the page to lock
+ * __lock_folio - Get a lock on the folio, assuming we need to sleep to get it.
+ * @folio: The folio to lock
  */
-void __lock_page(struct page *__page)
+void __lock_folio(struct folio *folio)
 {
-   struct page *page = compound_head(__page);
-   wait_queue_head_t *q = page_waitqueue(page);
-   wait_on_page_bit_common(q, page, PG_locked, TASK_UNINTERRUPTIBLE,
+   wait_queue_head_t *q = page_waitqueue(>page);
+   wait_on_page_bit_common(q, >page, PG_locked, 
TASK_UNINTERRUPTIBLE,
EXCLUSIVE);
 }
-EXPORT_SYMBOL(__lock_page);
+EXPORT_SYMBOL(__lock_folio);
 
 int __lock_page_killable(struct page *__page)
 {
@@ -1590,10 +1589,10 @@ int __lock_page_or_retry(struct page *page, struct 
mm_struct *mm,
return 0;
}
} else {
-   __lock_page(page);
+   __lock_folio(page_folio(page));
}
-   return 1;
 
+   return 1;
 }
 
 /**
@@ -2738,7 +2737,9 @@ loff_t mapping_seek_hole_data(struct address_space 
*mapping, loff_t start,
 static int lock_page_maybe_drop_mmap(struct vm_fault *vmf, struct page *page,
 struct file **fpin)
 {
-   if (trylock_page(page))
+   struct folio *folio = page_folio(page);
+
+   if (trylock_folio(folio))
return 1;
 
/*
@@ -2751,7 +2752,7 @@ static int lock_page_maybe_drop_mmap(struct vm_fault 
*vmf, struct page *page,
 
*fpin = maybe_unlock_mmap_for_io(vmf, *fpin);
if (vmf->flags & FAULT_FLAG_KILLABLE) {
-   if (__lock_page_killable(page)) {
+   if (__lock_page_killable(>page)) {
/*
 * We didn't have the right flags to drop the mmap_lock,
 * but all fault_handlers only check for fatal signals
@@ -2763,11 +2764,11 @@ static int lock_page_maybe_drop_mmap(struct vm_fault 
*vmf, struct page *page,
return 0;
}
} else
-   __lock_page(page);
+   __lock_folio(folio);
+
return 1;
 }
 
-
 /*
  * Synchronous readahead happens when we don't even find a page in the 

[PATCH v3 16/25] mm: Convert lock_page_async to lock_folio_async

2021-01-27 Thread Matthew Wilcox (Oracle)
When the caller already has a folio, this saves a call to compound_head().
If not, the call to compound_head() is merely moved.

Signed-off-by: Matthew Wilcox (Oracle) 
---
 fs/io_uring.c   |  2 +-
 include/linux/pagemap.h | 14 +++---
 mm/filemap.c| 12 ++--
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 03748faa5295..2627160ffd4c 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -3398,7 +3398,7 @@ static int io_read_prep(struct io_kiocb *req, const 
struct io_uring_sqe *sqe)
 }
 
 /*
- * This is our waitqueue callback handler, registered through lock_page_async()
+ * This is our waitqueue callback handler, registered through 
lock_folio_async()
  * when we initially tried to do the IO with the iocb armed our waitqueue.
  * This gets called when the page is unlocked, and we generally expect that to
  * happen when the page IO is completed and the page is now uptodate. This will
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 93a4ab9feaa8..131d1aa2af61 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -620,7 +620,7 @@ static inline bool wake_page_match(struct wait_page_queue 
*wait_page,
 
 void __lock_folio(struct folio *folio);
 int __lock_folio_killable(struct folio *folio);
-extern int __lock_page_async(struct page *page, struct wait_page_queue *wait);
+int __lock_folio_async(struct folio *folio, struct wait_page_queue *wait);
 extern int __lock_page_or_retry(struct page *page, struct mm_struct *mm,
unsigned int flags);
 void unlock_folio(struct folio *folio);
@@ -687,18 +687,18 @@ static inline int lock_page_killable(struct page *page)
 }
 
 /*
- * lock_page_async - Lock the page, unless this would block. If the page
- * is already locked, then queue a callback when the page becomes unlocked.
+ * lock_folio_async - Lock the folio, unless this would block. If the folio
+ * is already locked, then queue a callback when the folio becomes unlocked.
  * This callback can then retry the operation.
  *
- * Returns 0 if the page is locked successfully, or -EIOCBQUEUED if the page
+ * Returns 0 if the folio is locked successfully, or -EIOCBQUEUED if the folio
  * was already locked and the callback defined in 'wait' was queued.
  */
-static inline int lock_page_async(struct page *page,
+static inline int lock_folio_async(struct folio *folio,
  struct wait_page_queue *wait)
 {
-   if (!trylock_page(page))
-   return __lock_page_async(page, wait);
+   if (!trylock_folio(folio))
+   return __lock_folio_async(folio, wait);
return 0;
 }
 
diff --git a/mm/filemap.c b/mm/filemap.c
index c378b28c2bdc..a54eb4641385 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1524,18 +1524,18 @@ int __lock_folio_killable(struct folio *folio)
 }
 EXPORT_SYMBOL_GPL(__lock_folio_killable);
 
-int __lock_page_async(struct page *page, struct wait_page_queue *wait)
+int __lock_folio_async(struct folio *folio, struct wait_page_queue *wait)
 {
-   struct wait_queue_head *q = page_waitqueue(page);
+   struct wait_queue_head *q = page_waitqueue(>page);
int ret = 0;
 
-   wait->page = page;
+   wait->page = >page;
wait->bit_nr = PG_locked;
 
spin_lock_irq(>lock);
__add_wait_queue_entry_tail(q, >wait);
-   SetPageWaiters(page);
-   ret = !trylock_page(page);
+   SetFolioWaiters(folio);
+   ret = !trylock_folio(folio);
/*
 * If we were successful now, we know we're still on the
 * waitqueue as we're still under the lock. This means it's
@@ -2293,7 +2293,7 @@ static int filemap_update_page(struct kiocb *iocb,
put_and_wait_on_page_locked(page, TASK_KILLABLE);
return AOP_TRUNCATED_PAGE;
}
-   error = __lock_page_async(page, iocb->ki_waitq);
+   error = __lock_folio_async(page_folio(page), iocb->ki_waitq);
if (error)
return error;
}
-- 
2.29.2



[PATCH v3 18/25] mm: Convert wait_on_page_bit to wait_on_folio_bit

2021-01-27 Thread Matthew Wilcox (Oracle)
We must deal with folios here otherwise we'll get the wrong waitqueue
and fail to receive wakeups.

Signed-off-by: Matthew Wilcox (Oracle) 
---
 fs/afs/write.c  | 31 ---
 include/linux/pagemap.h | 19 +--
 mm/filemap.c| 54 ++---
 mm/page-writeback.c |  7 +++---
 4 files changed, 56 insertions(+), 55 deletions(-)

diff --git a/fs/afs/write.c b/fs/afs/write.c
index e672833c99bc..b3dac7afd123 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -915,13 +915,14 @@ int afs_fsync(struct file *file, loff_t start, loff_t 
end, int datasync)
  */
 vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)
 {
-   struct page *page = thp_head(vmf->page);
+   struct folio *folio = page_folio(vmf->page);
struct file *file = vmf->vma->vm_file;
struct inode *inode = file_inode(file);
struct afs_vnode *vnode = AFS_FS_I(inode);
unsigned long priv;
 
-   _enter("{{%llx:%llu}},{%lx}", vnode->fid.vid, vnode->fid.vnode, 
page->index);
+   _enter("{{%llx:%llu}},{%lx}", vnode->fid.vid, vnode->fid.vnode,
+   folio->page.index);
 
sb_start_pagefault(inode->i_sb);
 
@@ -929,32 +930,34 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)
 * be modified.  We then assume the entire page will need writing back.
 */
 #ifdef CONFIG_AFS_FSCACHE
-   if (PageFsCache(page) &&
-   wait_on_page_bit_killable(page, PG_fscache) < 0)
+   if (FolioFsCache(folio) &&
+   wait_on_folio_bit_killable(folio, PG_fscache) < 0)
return VM_FAULT_RETRY;
 #endif
 
-   if (PageWriteback(page) &&
-   wait_on_page_bit_killable(page, PG_writeback) < 0)
+   if (FolioWriteback(folio) &&
+   wait_on_folio_bit_killable(folio, PG_writeback) < 0)
return VM_FAULT_RETRY;
 
-   if (lock_page_killable(page) < 0)
+   if (lock_folio_killable(folio) < 0)
return VM_FAULT_RETRY;
 
/* We mustn't change page->private until writeback is complete as that
 * details the portion of the page we need to write back and we might
 * need to redirty the page if there's a problem.
 */
-   wait_on_page_writeback(page);
+   wait_on_page_writeback(>page);
 
-   priv = afs_page_dirty(page, 0, thp_size(page));
+   priv = afs_page_dirty(>page, 0, folio_size(folio));
priv = afs_page_dirty_mmapped(priv);
-   if (PagePrivate(page)) {
-   set_page_private(page, priv);
-   trace_afs_page_dirty(vnode, tracepoint_string("mkwrite+"), 
page);
+   if (FolioPrivate(folio)) {
+   set_folio_private(folio, priv);
+   trace_afs_page_dirty(vnode, tracepoint_string("mkwrite+"),
+   >page);
} else {
-   attach_page_private(page, (void *)priv);
-   trace_afs_page_dirty(vnode, tracepoint_string("mkwrite"), page);
+   attach_folio_private(folio, (void *)priv);
+   trace_afs_page_dirty(vnode, tracepoint_string("mkwrite"),
+   >page);
}
file_update_time(file);
 
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 67d3badc9fe0..55f3c1a8be3c 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -720,8 +720,8 @@ static inline int lock_page_or_retry(struct page *page, 
struct mm_struct *mm,
  * This is exported only for wait_on_page_locked/wait_on_page_writeback, etc.,
  * and should not be used directly.
  */
-extern void wait_on_page_bit(struct page *page, int bit_nr);
-extern int wait_on_page_bit_killable(struct page *page, int bit_nr);
+extern void wait_on_folio_bit(struct folio *folio, int bit_nr);
+extern int wait_on_folio_bit_killable(struct folio *folio, int bit_nr);
 
 /* 
  * Wait for a page to be unlocked.
@@ -732,15 +732,17 @@ extern int wait_on_page_bit_killable(struct page *page, 
int bit_nr);
  */
 static inline void wait_on_page_locked(struct page *page)
 {
-   if (PageLocked(page))
-   wait_on_page_bit(compound_head(page), PG_locked);
+   struct folio *folio = page_folio(page);
+   if (FolioLocked(folio))
+   wait_on_folio_bit(folio, PG_locked);
 }
 
 static inline int wait_on_page_locked_killable(struct page *page)
 {
-   if (!PageLocked(page))
+   struct folio *folio = page_folio(page);
+   if (!FolioLocked(folio))
return 0;
-   return wait_on_page_bit_killable(compound_head(page), PG_locked);
+   return wait_on_folio_bit_killable(folio, PG_locked);
 }
 
 /**
@@ -752,8 +754,9 @@ static inline int wait_on_page_locked_killable(struct page 
*page)
  */
 static inline void wait_on_page_fscache(struct page *page)
 {
-   if (PagePrivate2(page))
-   wait_on_page_bit(compound_head(page), PG_fscache);
+   struct folio *folio = page_folio(page);
+   if (FolioPrivate2(folio))
+  

Re: [PATCH v5] arm64: Enable perf events based hard lockup detector

2021-01-27 Thread Sumit Garg
Hi Will,

On Tue, 26 Jan 2021 at 19:48, Will Deacon  wrote:
>
> Hi Sumit,
>
> On Fri, Jan 15, 2021 at 05:31:41PM +0530, Sumit Garg wrote:
> > With the recent feature added to enable perf events to use pseudo NMIs
> > as interrupts on platforms which support GICv3 or later, its now been
> > possible to enable hard lockup detector (or NMI watchdog) on arm64
> > platforms. So enable corresponding support.
> >
> > One thing to note here is that normally lockup detector is initialized
> > just after the early initcalls but PMU on arm64 comes up much later as
> > device_initcall(). So we need to re-initialize lockup detection once
> > PMU has been initialized.
> >
> > Signed-off-by: Sumit Garg 
> > ---
>
> [...]
>
> > diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
> > index 3605f77a..bafb7c8 100644
> > --- a/arch/arm64/kernel/perf_event.c
> > +++ b/arch/arm64/kernel/perf_event.c
> > @@ -23,6 +23,8 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> > +#include 
> >
> >  /* ARMv8 Cortex-A53 specific event types. */
> >  #define ARMV8_A53_PERFCTR_PREF_LINEFILL  0xC2
> > @@ -1246,12 +1248,30 @@ static struct platform_driver armv8_pmu_driver = {
> >   .probe  = armv8_pmu_device_probe,
> >  };
> >
> > +static int __init lockup_detector_init_fn(void *data)
> > +{
> > + lockup_detector_init();
> > + return 0;
> > +}
> > +
> >  static int __init armv8_pmu_driver_init(void)
> >  {
> > + int ret;
> > +
> >   if (acpi_disabled)
> > - return platform_driver_register(_pmu_driver);
> > + ret = platform_driver_register(_pmu_driver);
> >   else
> > - return arm_pmu_acpi_probe(armv8_pmuv3_init);
> > + ret = arm_pmu_acpi_probe(armv8_pmuv3_init);
> > +
> > + /*
> > +  * Try to re-initialize lockup detector after PMU init in
> > +  * case PMU events are triggered via NMIs.
> > +  */
> > + if (ret == 0 && arm_pmu_irq_is_nmi())
> > + smp_call_on_cpu(raw_smp_processor_id(), 
> > lockup_detector_init_fn,
> > + NULL, false);
> > +
> > + return ret;
>
> What's wrong with the alternative approach outlined by Mark:
>
> https://lore.kernel.org/r/20210113130235.GB19011@C02TD0UTHF1T.local
>
> ?

I have replied on this thread.

-Sumit

>
> Will


  1   2   3   4   5   6   7   8   9   10   >