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=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 6AEE1C432C0 for ; Tue, 3 Dec 2019 05:50:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3CDCE20659 for ; Tue, 3 Dec 2019 05:50:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727015AbfLCFu4 (ORCPT ); Tue, 3 Dec 2019 00:50:56 -0500 Received: from mga03.intel.com ([134.134.136.65]:28046 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726661AbfLCFuz (ORCPT ); Tue, 3 Dec 2019 00:50:55 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Dec 2019 21:50:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,272,1571727600"; d="scan'208";a="213289692" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by orsmga006.jf.intel.com with ESMTP; 02 Dec 2019 21:50:54 -0800 Date: Mon, 2 Dec 2019 21:50:54 -0800 From: Sean Christopherson To: Peter Xu Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , "Dr . David Alan Gilbert" , Vitaly Kuznetsov Subject: Re: [PATCH RFC 03/15] KVM: Add build-time error check on kvm_run size Message-ID: <20191203055054.GL8120@linux.intel.com> References: <20191129213505.18472-1-peterx@redhat.com> <20191129213505.18472-4-peterx@redhat.com> <20191202193027.GH4063@linux.intel.com> <20191202205315.GD31681@xz-x1> <20191202221949.GD8120@linux.intel.com> <20191202224034.GH31681@xz-x1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191202224034.GH31681@xz-x1> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 02, 2019 at 05:40:34PM -0500, Peter Xu wrote: > On Mon, Dec 02, 2019 at 02:19:49PM -0800, Sean Christopherson wrote: > > On Mon, Dec 02, 2019 at 03:53:15PM -0500, Peter Xu wrote: > > > On Mon, Dec 02, 2019 at 11:30:27AM -0800, Sean Christopherson wrote: > > > > On Fri, Nov 29, 2019 at 04:34:53PM -0500, Peter Xu wrote: > > > > > It's already going to reach 2400 Bytes (which is over half of page > > > > > size on 4K page archs), so maybe it's good to have this build-time > > > > > check in case it overflows when adding new fields. > > > > > > > > Please explain why exceeding PAGE_SIZE is a bad thing. I realize it's > > > > almost absurdly obvious when looking at the code, but a) the patch itself > > > > does not provide that context and b) the changelog should hold up on its > > > > own, > > > > > > Right, I'll enhance the commit message. > > > > > > > e.g. in a mostly hypothetical case where the allocation of vcpu->run > > > > were changed to something else. > > > > > > And that's why I added BUILD_BUG_ON right beneath that allocation. :) > > > > My point is that if the allocation were changed to no longer be a > > straightforward alloc_page() then someone reading the combined code would > > have no idea why the BUILD_BUG_ON() exists. It's a bit ridiculous for > > this case because the specific constraints of vcpu->run make it highly > > unlikely to use anything else, but that's beside the point. > > > > > It's just a helper for developers when adding new kvm_run fields, not > > > a risk for anyone who wants to start allocating more pages for it. > > > > But by adding a BUILD_BUG_ON without explaining *why*, you're placing an > > extra burden on someone that wants to increase the size of kvm->run, e.g. > > it's not at all obvious from the changelog whether this patch is adding > > the BUILD_BUG_ON purely because the code allocates memory for vcpu->run > > via alloc_page(), or if there is some fundamental aspect of vcpu->run that > > requires it to never span multiple pages. > > How about I add a comment above it? > > /* > * Currently kvm_run only uses one physical page. Warn the develper > * if kvm_run accidentaly grows more than that. > */ > BUILD_BUG_ON(...); No need for a comment, adding a blurb in the changelog is sufficient. The lengthy response was just trying to explain why it's helpful to explicitly justify a change that may seem obvious in the current codebase. Apologies if it only confused things.