From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F708C072AD for ; Tue, 21 May 2019 17:22:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3B2682182B for ; Tue, 21 May 2019 17:22:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729187AbfEURWH (ORCPT ); Tue, 21 May 2019 13:22:07 -0400 Received: from shelob.surriel.com ([96.67.55.147]:37336 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728127AbfEURWF (ORCPT ); Tue, 21 May 2019 13:22:05 -0400 Received: from [2603:3005:d05:2b00:6e0b:84ff:fee2:98bb] (helo=imladris.surriel.com) by shelob.surriel.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hT8Si-0004YY-3a; Tue, 21 May 2019 13:22:04 -0400 Date: Tue, 21 May 2019 13:22:00 -0400 From: Rik van Riel To: "Paolo Bonzini" Cc: kernel-team@fb.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Radim =?UTF-8?B?S3LEjW3DocWZ?=" Subject: [PATCH] kvm: change KVM_REQUEST_MASK to reflect vcpu.requests size Message-ID: <20190521132200.2b45c029@imladris.surriel.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code using KVM_REQUEST_MASK uses a pattern reminiscent of a bitmask: set_bit(req & KVM_REQUEST_MASK, &vcpu->requests); However, the first argument passed to set_bit, test_bit, and clear_bit is a bit number, not a bitmask. That means the current definition would allow users of kvm_make_request to overflow the vcpu.requests bitmask, and is confusing to developers examining the code. Redefine KVM_REQUEST_MASK to reflect the number of bits that actually fit inside an unsigned long, and add a comment explaining set_bit and friends take bit numbers, not a bitmask. Signed-off-by: Rik van Riel --- include/linux/kvm_host.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 79fa4426509c..d15fb43d7796 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -138,7 +138,8 @@ static inline bool is_error_page(struct page *page) return IS_ERR(page); } -#define KVM_REQUEST_MASK GENMASK(7,0) +/* Limit the bit numbers for set_bit etc to fit unsigned long vcpu.requests. */ +#define KVM_REQUEST_MASK (BITS_PER_LONG-1) #define KVM_REQUEST_NO_WAKEUP BIT(8) #define KVM_REQUEST_WAIT BIT(9) /*