Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1285256ybm; Tue, 21 May 2019 11:30:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxExjhY4pgx37NNHYn71EnMg8E0A+JiYnDa3eFDnTWlNACZzsMH6yIohkJTKILLiuwhaauL X-Received: by 2002:a63:6884:: with SMTP id d126mr84399711pgc.154.1558463426642; Tue, 21 May 2019 11:30:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558463426; cv=none; d=google.com; s=arc-20160816; b=AGdNjhs8v7wT9OOsFd2mYmtTJ1FhUOpCP5BnAof+u4yPaEJLPpixQHS69zDb6QbSyI tUo2x8/8a/HvlliMNDEBpRLJNNubj3cxczVCmzr4nSnHwG3KpGtYrXqeeHc+XFb4Go5B P0DcUt+8keZatds3Ur07Q/ziTjfWQ7lV3uj3+ZU0fq6fLvlkTLddNeJK/PPyordaq1u8 8pfjLQ/MuPxOb/hLge+BqMC1A3Xxc03wgrqfNdKhWhImyDy6CzKQv52YwIfggMlsssHp n92YjFsKe/ROa1jABFoVUsD+LctZ++n3K1FR/JMBPaHdDvE76MCACEuoU3FlH1sv039A SIiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=qU0oxwfZcLk0iOxgnO8VPxDjgRoJbZAj9hi3V2Z/tgY=; b=wQLa0M3LS8pQFqJxZ522ZNM79gWq24zwbe2qj0AQKymvtmt1DkraD1vz0TimJVJgDH x3esDjsBBIqe62EgC0FH07uS5P3pLt9E7PfiWeRv7QHHpOhcC8byITZSqFuUM+XfcFce mnzcFSQOQfsdtreZ3LPKa0GZSF0qzZ8bjcF/C4bp1Gn5l+YbDU8Rk5qoYS+iJLHbd0mY jxzd4GeHOAm7uH/YELcwTYV5rfXyeHNpcoWpCOdZPndZbvSKfT47gOpxQjmf+EDHqnjF 5dUGjLnMnmZWkOt9oxnSkIROnW+OzVRg2IjIl6vMxdsRue2VRfkII5JzA5YWd7EJ+Ztx v9pw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v1si4362822plo.191.2019.05.21.11.30.10; Tue, 21 May 2019 11:30:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729233AbfEUS2k (ORCPT + 99 others); Tue, 21 May 2019 14:28:40 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:54778 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728337AbfEUS2k (ORCPT ); Tue, 21 May 2019 14:28:40 -0400 Received: by mail-wm1-f66.google.com with SMTP id i3so3955884wml.4 for ; Tue, 21 May 2019 11:28:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qU0oxwfZcLk0iOxgnO8VPxDjgRoJbZAj9hi3V2Z/tgY=; b=cQPO7/UQbMhClECuzv/x40WLa4kz3nYyyPsUKJXtSD2mTc5nswgKOcdiA84CFdEM3Z 4fQ2mT1p7E1DqZqJRBEfwFJcCWVadc3Doat1Y7Vd0gfDi7TwlKzp3vmg39VBVE5JlFfR /zfcNDUhlfr6zRHiNxfT3ToF7HYa/yylRAhbDl7Kk0pt6ZpxGTjPAGpjEbKODUvMwvL4 ubxwZ/TgOv5NeEIU7DyjyBuHhQ6ZLMqi7o20IPdAPTr/hVeG77AAtnbWOQj/B1XkgUiK 2MOY7eyeS306GrnJ0SADBJxl9yoK2HX/1dFLpWO6ClzAWzOWQVA0lJnf2n7K/H4YJQH3 2eqQ== X-Gm-Message-State: APjAAAUO0e673EpoxtYkDy1e+p1r84LgqKv5g/JHu5N8NC/LNNur7spP zNWyZ2+nuS8QDq8VgguaaBb9LQ== X-Received: by 2002:a1c:ed07:: with SMTP id l7mr4253630wmh.148.1558463317936; Tue, 21 May 2019 11:28:37 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:ac04:eef9:b257:b844? ([2001:b07:6468:f312:ac04:eef9:b257:b844]) by smtp.gmail.com with ESMTPSA id s127sm4011028wmf.48.2019.05.21.11.28.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 May 2019 11:28:37 -0700 (PDT) Subject: Re: [PATCH] kvm: change KVM_REQUEST_MASK to reflect vcpu.requests size To: Rik van Riel Cc: kernel-team@fb.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= References: <20190521132200.2b45c029@imladris.surriel.com> From: Paolo Bonzini Message-ID: Date: Tue, 21 May 2019 20:28:36 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190521132200.2b45c029@imladris.surriel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21/05/19 19:22, Rik van Riel wrote: > 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. This is true, but the meaning of the masking is that bits above 7 define extra things to do when sending a request (wait for acknowledge, kick the recipient CPU). The fact that the "request number" field is 8 bits rather than 5 or 6 is just an implementation detail. If you change it to BITS_PER_LONG-1, the obvious way to read the code would be that requests 0, 64, 128 are all valid and map to the same request. Paolo > 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.