linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kvm: x86: mmu: Add cast to negated bitmasks in update_permission_bitmask()
@ 2018-06-15 17:47 Matthias Kaehlcke
  2018-06-15 18:04 ` Nick Desaulniers
  2018-06-16  3:39 ` kbuild test robot
  0 siblings, 2 replies; 23+ messages in thread
From: Matthias Kaehlcke @ 2018-06-15 17:47 UTC (permalink / raw)
  To: Paolo Bonzini, Radim Krčmář, Thomas Gleixner,
	H . Peter Anvin
  Cc: x86, kvm, linux-kernel, Nick Desaulniers, Matthias Kaehlcke

update_permission_bitmask() negates u8 bitmask values and assigns them
to variables of type u8. Since the MSB is set in the bitmask values the
compiler expands the negated values to int, which then are assigned to
u8 variables. Cast the negated values back to u8.

This fixes several warnings like this when building with clang:

arch/x86/kvm/mmu.c:4266:39: error: implicit conversion from 'int' to 'u8'
  (aka 'unsigned char') changes value from -205 to 51 [-Werror,
  -Wconstant-conversion]
    u8 wf = (pfec & PFERR_WRITE_MASK) ? ~w : 0;
       ~~                               ^~

(gcc also raises a warning (see https://godbolt.org/g/6JWfWk), however it
doesn't seem to be universally enabled)

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
 arch/x86/kvm/mmu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index d634f0332c0f..a83817fdbd87 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -4275,11 +4275,11 @@ static void update_permission_bitmask(struct kvm_vcpu *vcpu,
 		 */
 
 		/* Faults from writes to non-writable pages */
-		u8 wf = (pfec & PFERR_WRITE_MASK) ? ~w : 0;
+		u8 wf = (pfec & PFERR_WRITE_MASK) ? (u8)~w : 0;
 		/* Faults from user mode accesses to supervisor pages */
-		u8 uf = (pfec & PFERR_USER_MASK) ? ~u : 0;
+		u8 uf = (pfec & PFERR_USER_MASK) ? (u8)~u : 0;
 		/* Faults from fetches of non-executable pages*/
-		u8 ff = (pfec & PFERR_FETCH_MASK) ? ~x : 0;
+		u8 ff = (pfec & PFERR_FETCH_MASK) ? (u8)~x : 0;
 		/* Faults from kernel mode fetches of user pages */
 		u8 smepf = 0;
 		/* Faults from kernel mode accesses of user pages */
-- 
2.18.0.rc1.244.gcf134e6275-goog


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2018-06-20 23:00 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-15 17:47 [PATCH] kvm: x86: mmu: Add cast to negated bitmasks in update_permission_bitmask() Matthias Kaehlcke
2018-06-15 18:04 ` Nick Desaulniers
2018-06-15 18:18   ` Joe Perches
2018-06-15 18:29     ` Matthias Kaehlcke
2018-06-15 18:40       ` Joe Perches
2018-06-15 18:45         ` Nick Desaulniers
2018-06-19 15:19           ` Paolo Bonzini
2018-06-19 17:08             ` Nick Desaulniers
2018-06-19 17:13               ` Paolo Bonzini
2018-06-19 18:38                 ` Matthias Kaehlcke
2018-06-19 17:23               ` Joe Perches
2018-06-19 17:35                 ` Paolo Bonzini
2018-06-19 18:07                   ` Joe Perches
2018-06-19 18:36                     ` Matthias Kaehlcke
2018-06-19 19:11                       ` Joe Perches
2018-06-19 21:10                         ` Matthias Kaehlcke
2018-06-19 21:55                           ` Joe Perches
2018-06-19 23:45                             ` Matthias Kaehlcke
2018-06-20  0:18                               ` Joe Perches
2018-06-20  1:36                                 ` Matthias Kaehlcke
2018-06-20  8:02                               ` Paolo Bonzini
2018-06-20 23:00                                 ` Matthias Kaehlcke
2018-06-16  3:39 ` kbuild test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).