Message ID | 20190627125521.10782-1-tvrtko.ursulin@linux.intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [i-g-t] lib: Silence Valgrind warning in synce_fence_status | expand |
Quoting Tvrtko Ursulin (2019-06-27 13:55:21) > From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > > Let Valgrind know the ioctl initializes the passed in info block to reduce > the noise while debugging. > > Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > --- > lib/sw_sync.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/lib/sw_sync.c b/lib/sw_sync.c > index f208603312c2..73f3f7015d9d 100644 > --- a/lib/sw_sync.c > +++ b/lib/sw_sync.c > @@ -41,6 +41,15 @@ > #include "drmtest.h" > #include "ioctl_wrappers.h" > > +#ifdef HAVE_VALGRIND > +#include <valgrind/valgrind.h> > +#include <valgrind/memcheck.h> > + > +#define VG(x) x > +#else > +#define VG(x) do {} while (0) > +#endif > + > /** > * SECTION:sw_sync > * @short_description: Software sync (fencing) support library > @@ -218,6 +227,8 @@ int sync_fence_status(int fence) > if (file_info.num_fences != 1) > return -EINVAL; ^ Otherwise known as lets pretend we never saw that kernel bug. https://patchwork.freedesktop.org/patch/311883/?series=62278&rev=1 An example of why igt should not be filtering the kernel. Just complaining because Petri found a bug in one of tests that is being blocked by no one reviewing the kernel fix that is blocking fixing the library to allow the bug fix in the test. > + VG(VALGRIND_MAKE_MEM_DEFINED(&fence_info, sizeof(fence_info))); More fun would be to struct sync_fence_info fence_info = { .status = -ENOSYS }; So that valgrind knows it is initialised and we reliably report an error if the kernel fails to fill in the struct. -Chris
On 27/06/2019 14:06, Chris Wilson wrote: > Quoting Tvrtko Ursulin (2019-06-27 13:55:21) >> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >> >> Let Valgrind know the ioctl initializes the passed in info block to reduce >> the noise while debugging. >> >> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >> --- >> lib/sw_sync.c | 11 +++++++++++ >> 1 file changed, 11 insertions(+) >> >> diff --git a/lib/sw_sync.c b/lib/sw_sync.c >> index f208603312c2..73f3f7015d9d 100644 >> --- a/lib/sw_sync.c >> +++ b/lib/sw_sync.c >> @@ -41,6 +41,15 @@ >> #include "drmtest.h" >> #include "ioctl_wrappers.h" >> >> +#ifdef HAVE_VALGRIND >> +#include <valgrind/valgrind.h> >> +#include <valgrind/memcheck.h> >> + >> +#define VG(x) x >> +#else >> +#define VG(x) do {} while (0) >> +#endif >> + >> /** >> * SECTION:sw_sync >> * @short_description: Software sync (fencing) support library >> @@ -218,6 +227,8 @@ int sync_fence_status(int fence) >> if (file_info.num_fences != 1) >> return -EINVAL; > > ^ Otherwise known as lets pretend we never saw that kernel bug. > https://patchwork.freedesktop.org/patch/311883/?series=62278&rev=1 > > An example of why igt should not be filtering the kernel. You think the library helper shouldn't be testing for num_fences == 1, eg the same as passed in? It is questionable that it should return -EINVAL in this case I agree with that. If that's what you meant with filtering. > Just complaining because Petri found a bug in one of tests that is being > blocked by no one reviewing the kernel fix that is blocking fixing the > library to allow the bug fix in the test. It's only related because it's the same ioctl. :) But... >> + VG(VALGRIND_MAKE_MEM_DEFINED(&fence_info, sizeof(fence_info))); > > More fun would be to > > struct sync_fence_info fence_info = { .status = -ENOSYS }; > > So that valgrind knows it is initialised and we reliably report an error > if the kernel fails to fill in the struct. ... sure, this is also okay. For me -ENOSYS is not strictly needed at this level. It would be more of a unit test for the ioctl, not belonging to the library helper, but it is also fine to inject some more explicit trash so it can be caught even if there are no specific unit tests. I don't also see a problem with Valgrind annotation. It doesn't hide anything, nor does it sanitises. But yes, it is not needed if we go for -ENOSYS trick. Regards, Tvrtko
On Thu, 27 Jun 2019, Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com> wrote: > From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > > Let Valgrind know the ioctl initializes the passed in info block to reduce > the noise while debugging. > > Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > --- > lib/sw_sync.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/lib/sw_sync.c b/lib/sw_sync.c > index f208603312c2..73f3f7015d9d 100644 > --- a/lib/sw_sync.c > +++ b/lib/sw_sync.c > @@ -41,6 +41,15 @@ > #include "drmtest.h" > #include "ioctl_wrappers.h" > > +#ifdef HAVE_VALGRIND > +#include <valgrind/valgrind.h> > +#include <valgrind/memcheck.h> > + > +#define VG(x) x > +#else > +#define VG(x) do {} while (0) OOC, why not just #define VALGRIND_MAKE_MEM_DEFINED(...) BR, Jani. > +#endif > + > /** > * SECTION:sw_sync > * @short_description: Software sync (fencing) support library > @@ -218,6 +227,8 @@ int sync_fence_status(int fence) > if (file_info.num_fences != 1) > return -EINVAL; > > + VG(VALGRIND_MAKE_MEM_DEFINED(&fence_info, sizeof(fence_info))); > + > return fence_info.status; > }
On 27/06/2019 14:59, Jani Nikula wrote: > On Thu, 27 Jun 2019, Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com> wrote: >> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >> >> Let Valgrind know the ioctl initializes the passed in info block to reduce >> the noise while debugging. >> >> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >> --- >> lib/sw_sync.c | 11 +++++++++++ >> 1 file changed, 11 insertions(+) >> >> diff --git a/lib/sw_sync.c b/lib/sw_sync.c >> index f208603312c2..73f3f7015d9d 100644 >> --- a/lib/sw_sync.c >> +++ b/lib/sw_sync.c >> @@ -41,6 +41,15 @@ >> #include "drmtest.h" >> #include "ioctl_wrappers.h" >> >> +#ifdef HAVE_VALGRIND >> +#include <valgrind/valgrind.h> >> +#include <valgrind/memcheck.h> >> + >> +#define VG(x) x >> +#else >> +#define VG(x) do {} while (0) > > OOC, why not just > > #define VALGRIND_MAKE_MEM_DEFINED(...) Copy and paste isn't an established practice? :)) Regards, Tvrtko
Quoting Jani Nikula (2019-06-27 14:59:52) > On Thu, 27 Jun 2019, Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com> wrote: > > From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > > > > Let Valgrind know the ioctl initializes the passed in info block to reduce > > the noise while debugging. > > > > Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > > --- > > lib/sw_sync.c | 11 +++++++++++ > > 1 file changed, 11 insertions(+) > > > > diff --git a/lib/sw_sync.c b/lib/sw_sync.c > > index f208603312c2..73f3f7015d9d 100644 > > --- a/lib/sw_sync.c > > +++ b/lib/sw_sync.c > > @@ -41,6 +41,15 @@ > > #include "drmtest.h" > > #include "ioctl_wrappers.h" > > > > +#ifdef HAVE_VALGRIND > > +#include <valgrind/valgrind.h> > > +#include <valgrind/memcheck.h> > > + > > +#define VG(x) x > > +#else > > +#define VG(x) do {} while (0) > > OOC, why not just > > #define VALGRIND_MAKE_MEM_DEFINED(...) Once upon a time, in a project far far away, VG() was used to conditionally compile code for extra debug under valgrind and so the pattern took root. -Chris
On Thu, 27 Jun 2019, Jani Nikula <jani.nikula@linux.intel.com> wrote: > On Thu, 27 Jun 2019, Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com> wrote: >> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >> >> Let Valgrind know the ioctl initializes the passed in info block to reduce >> the noise while debugging. >> >> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >> --- >> lib/sw_sync.c | 11 +++++++++++ >> 1 file changed, 11 insertions(+) >> >> diff --git a/lib/sw_sync.c b/lib/sw_sync.c >> index f208603312c2..73f3f7015d9d 100644 >> --- a/lib/sw_sync.c >> +++ b/lib/sw_sync.c >> @@ -41,6 +41,15 @@ >> #include "drmtest.h" >> #include "ioctl_wrappers.h" >> >> +#ifdef HAVE_VALGRIND >> +#include <valgrind/valgrind.h> >> +#include <valgrind/memcheck.h> >> + >> +#define VG(x) x >> +#else >> +#define VG(x) do {} while (0) > > OOC, why not just > > #define VALGRIND_MAKE_MEM_DEFINED(...) And to underline, this is not a request to change anything! BR, Jani. > > BR, > Jani. > >> +#endif >> + >> /** >> * SECTION:sw_sync >> * @short_description: Software sync (fencing) support library >> @@ -218,6 +227,8 @@ int sync_fence_status(int fence) >> if (file_info.num_fences != 1) >> return -EINVAL; >> >> + VG(VALGRIND_MAKE_MEM_DEFINED(&fence_info, sizeof(fence_info))); >> + >> return fence_info.status; >> }
Quoting Tvrtko Ursulin (2019-06-27 14:59:10) > > On 27/06/2019 14:06, Chris Wilson wrote: > >> + VG(VALGRIND_MAKE_MEM_DEFINED(&fence_info, sizeof(fence_info))); > > > > More fun would be to > > > > struct sync_fence_info fence_info = { .status = -ENOSYS }; > > > > So that valgrind knows it is initialised and we reliably report an error > > if the kernel fails to fill in the struct. > > ... sure, this is also okay. For me -ENOSYS is not strictly needed at > this level. It would be more of a unit test for the ioctl, not belonging > to the library helper, but it is also fine to inject some more explicit > trash so it can be caught even if there are no specific unit tests. > > I don't also see a problem with Valgrind annotation. It doesn't hide > anything, nor does it sanitises. But yes, it is not needed if we go for > -ENOSYS trick. That's all I was thinking, two birds one stone. I think it is a bonus if we don't paper over the kernel randomly serving up garbage -- but at the same time random failures are not the easiest to debug. But at least they serve as canaries. -Chris
diff --git a/lib/sw_sync.c b/lib/sw_sync.c index f208603312c2..73f3f7015d9d 100644 --- a/lib/sw_sync.c +++ b/lib/sw_sync.c @@ -41,6 +41,15 @@ #include "drmtest.h" #include "ioctl_wrappers.h" +#ifdef HAVE_VALGRIND +#include <valgrind/valgrind.h> +#include <valgrind/memcheck.h> + +#define VG(x) x +#else +#define VG(x) do {} while (0) +#endif + /** * SECTION:sw_sync * @short_description: Software sync (fencing) support library @@ -218,6 +227,8 @@ int sync_fence_status(int fence) if (file_info.num_fences != 1) return -EINVAL; + VG(VALGRIND_MAKE_MEM_DEFINED(&fence_info, sizeof(fence_info))); + return fence_info.status; }