From patchwork Tue May 21 17:22:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rik van Riel X-Patchwork-Id: 10954347 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F4D976 for ; Tue, 21 May 2019 17:22:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4132A28717 for ; Tue, 21 May 2019 17:22:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35C6628A60; Tue, 21 May 2019 17:22:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0258328717 for ; Tue, 21 May 2019 17:22:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729164AbfEURWF (ORCPT ); Tue, 21 May 2019 13:22:05 -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 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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) /*