Message ID | 20190123163049.24863-3-joro@8bytes.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Fix virtio-blk issue with SWIOTLB | expand |
On Wed, Jan 23, 2019 at 05:30:46PM +0100, Joerg Roedel wrote: > +bool is_swiotlb_active(void) > +{ > + return !no_iotlb_memory; > +} As I've just introduced and fixed a bug in this area in the current cycle - I don't think no_iotlb_memory is what your want (and maybe not useful at all): if the arch valls swiotlb_exit after previously initializing a buffer it won't be set. You probably want to check for non-zero io_tlb_start and/or io_tlb_end.
On Wed, Jan 23, 2019 at 10:27:55PM +0100, Christoph Hellwig wrote: > On Wed, Jan 23, 2019 at 05:30:46PM +0100, Joerg Roedel wrote: > > +bool is_swiotlb_active(void) > > +{ > > + return !no_iotlb_memory; > > +} > > As I've just introduced and fixed a bug in this area in the current > cycle - I don't think no_iotlb_memory is what your want (and maybe > not useful at all): if the arch valls swiotlb_exit after previously > initializing a buffer it won't be set. You probably want to check > for non-zero io_tlb_start and/or io_tlb_end. Okay, but that requires that I also set io_tlb_start and friends back to zero in the failure path of swiotlb_init(). Otherwise it could be left non-zero in case swiotlb_init_with_tbl() returns an error. Regards, Joerg
On Thu, Jan 24, 2019 at 09:29:23AM +0100, Joerg Roedel wrote: > > As I've just introduced and fixed a bug in this area in the current > > cycle - I don't think no_iotlb_memory is what your want (and maybe > > not useful at all): if the arch valls swiotlb_exit after previously > > initializing a buffer it won't be set. You probably want to check > > for non-zero io_tlb_start and/or io_tlb_end. > > Okay, but that requires that I also set io_tlb_start and friends back to > zero in the failure path of swiotlb_init(). Otherwise it could be left > non-zero in case swiotlb_init_with_tbl() returns an error. Indeed, and we'll need to do that anyway as otherwise the dma mapping path might cause problems similar to the one when swiotlb_exit is called that I fixed.
On Thu, Jan 24, 2019 at 09:41:07AM +0100, Christoph Hellwig wrote: > On Thu, Jan 24, 2019 at 09:29:23AM +0100, Joerg Roedel wrote: > > > As I've just introduced and fixed a bug in this area in the current > > > cycle - I don't think no_iotlb_memory is what your want (and maybe > > > not useful at all): if the arch valls swiotlb_exit after previously > > > initializing a buffer it won't be set. You probably want to check > > > for non-zero io_tlb_start and/or io_tlb_end. > > > > Okay, but that requires that I also set io_tlb_start and friends back to > > zero in the failure path of swiotlb_init(). Otherwise it could be left > > non-zero in case swiotlb_init_with_tbl() returns an error. > > Indeed, and we'll need to do that anyway as otherwise the dma mapping > path might cause problems similar to the one when swiotlb_exit is > called that I fixed. Turns out the the error path in swiotlb_init() is redundant because it will never be executed. If the function returns it will always return 0 because in case of failure it will just panic (through memblock_alloc). I'll clean that up in a separate patch-set. There are more users of that function and all of them panic when the function fails. Joerg
On Thu, Jan 24, 2019 at 04:00:00PM +0100, Joerg Roedel wrote: > On Thu, Jan 24, 2019 at 09:41:07AM +0100, Christoph Hellwig wrote: > > On Thu, Jan 24, 2019 at 09:29:23AM +0100, Joerg Roedel wrote: > > > > As I've just introduced and fixed a bug in this area in the current > > > > cycle - I don't think no_iotlb_memory is what your want (and maybe > > > > not useful at all): if the arch valls swiotlb_exit after previously > > > > initializing a buffer it won't be set. You probably want to check > > > > for non-zero io_tlb_start and/or io_tlb_end. > > > > > > Okay, but that requires that I also set io_tlb_start and friends back to > > > zero in the failure path of swiotlb_init(). Otherwise it could be left > > > non-zero in case swiotlb_init_with_tbl() returns an error. > > > > Indeed, and we'll need to do that anyway as otherwise the dma mapping > > path might cause problems similar to the one when swiotlb_exit is > > called that I fixed. > > Turns out the the error path in swiotlb_init() is redundant because it > will never be executed. If the function returns it will always return 0 > because in case of failure it will just panic (through memblock_alloc). > > I'll clean that up in a separate patch-set. There are more users of that > function and all of them panic when the function fails. > > > Joerg OK so are you going to post a new version then? Time's running out for 5.0. This isn't a regression so maybe we should just defer it all to 5.1.
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index ceb623321f38..5c087d330b4b 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -63,6 +63,7 @@ extern void swiotlb_tbl_sync_single(struct device *hwdev, extern int swiotlb_dma_supported(struct device *hwdev, u64 mask); extern size_t swiotlb_max_mapping_size(struct device *dev); +bool is_swiotlb_active(void); #ifdef CONFIG_SWIOTLB extern enum swiotlb_force swiotlb_force; @@ -100,6 +101,11 @@ static inline size_t swiotlb_max_mapping_size(struct device *dev) { return SIZE_MAX; } + +static inline bool is_swiotlb_active(void) +{ + return false; +} #endif /* CONFIG_SWIOTLB */ extern void swiotlb_print_info(void); diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 9cb21259cb0b..9fbd075081d9 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -667,3 +667,8 @@ size_t swiotlb_max_mapping_size(struct device *dev) { return ((size_t)1 << IO_TLB_SHIFT) * IO_TLB_SEGSIZE; } + +bool is_swiotlb_active(void) +{ + return !no_iotlb_memory; +}