lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 1 Mar 2012 15:23:14 -0500
From:	Muthu Kumar <muthu.lkml@...il.com>
To:	Andrew Morton <akpm@...ux-foundation.org>
Cc:	linux-kernel@...r.kernel.org, torvalds@...ux-foundation.org,
	Jens Axboe <axboe@...nel.dk>, martin.petersen@...cle.com
Subject: Re: [PATCH] Fix setting bio flags in drivers (sd_dif/floppy).

>>                       kunmap_atomic(sdt, KM_USER0);
>>               }
>>
>> -             bio->bi_flags |= BIO_MAPPED_INTEGRITY;
>> +             bio->bi_flags |= (1 << BIO_MAPPED_INTEGRITY);
>>       }
>>
>>       return 0;
>
> urgh.  This isn't the first time.
>
> It's too easy for people to make this mistake.  I'm not sure what a
> good fix would be - I don't think sparse can save us with __bitwise or
> similar.
>
> The approach we took in buffer_head.h with BH_Foo and BUFFER_FNS
> accessors worked pretty well.
>

Does this look good? BTW, I used the non-atomic variants __set/__clear
to match the behavior of current usage.
If this looks good, I can send the proper patch as attachment (so no
line wraps :)


diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 4053cbd..8b2fbbb 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -8,6 +8,7 @@
 #ifdef CONFIG_BLOCK

 #include <linux/types.h>
+#include <linux/bitops.h>

 struct bio_set;
 struct bio;
@@ -98,6 +99,43 @@ struct bio {
 #define bio_flagged(bio, flag) ((bio)->bi_flags & (1 << (flag)))

 /*
+ * Macro tricks similar to setting b_state in buffer_head.h.
+ * To set uptodate flag in a bio:
+ *      bio_flags_set_uptodate(bio);
+ * To clear
+ *      bio_flags_clear_uptodate(bio);
+ * To test if it is set
+ *      bio_flagged_uptodate(bio);
+ */
+#define BIO_FLAGS_FNS(bit, name)                                         \
+static inline void bio_flags_set_##name(struct bio *bio)                 \
+{                                                                        \
+    __set_bit(BIO_##bit, &(bio)->bi_flags);                              \
+}                                                                        \
+static inline void bio_flags_clear_##name(struct bio *bio)               \
+{                                                                        \
+    __clear_bit(BIO_##bit, &(bio)->bi_flags);                            \
+}                                                                        \
+static inline int bio_flagged_##name(const struct bio *bio)              \
+{                                                                        \
+    return test_bit(BIO_##bit, &(bio)->bi_flags);                        \
+}                                                                        \
+
+BIO_FLAGS_FNS(UPTODATE, uptodate)
+BIO_FLAGS_FNS(RW_BLOCK, rw_block)
+BIO_FLAGS_FNS(EOF, eof)
+BIO_FLAGS_FNS(SEG_VALID, seg_valid)
+BIO_FLAGS_FNS(CLONED, cloned)
+BIO_FLAGS_FNS(BOUNCED, bounced)
+BIO_FLAGS_FNS(USER_MAPPED, user_mapped)
+BIO_FLAGS_FNS(EOPNOTSUPP, eopnotsupp)
+BIO_FLAGS_FNS(NULL_MAPPED, null_mapped)
+BIO_FLAGS_FNS(FS_INTEGRITY, fs_integrity)
+BIO_FLAGS_FNS(QUIET, quiet)
+BIO_FLAGS_FNS(MAPPED_INTEGRITY, mapped_integrity)
+
+/*
  * top 4 bits of bio flags indicate the pool this bio came from
  */
 #define BIO_POOL_BITS          (4)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ