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=-8.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 78475C433E0 for ; Wed, 15 Jul 2020 12:43:02 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 563B920578 for ; Wed, 15 Jul 2020 12:43:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 563B920578 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jvgkL-0005tu-Dm; Wed, 15 Jul 2020 12:42:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jvgkK-0005tp-6X for xen-devel@lists.xenproject.org; Wed, 15 Jul 2020 12:42:48 +0000 X-Inumbo-ID: af704d1a-c698-11ea-bca7-bc764e2007e4 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id af704d1a-c698-11ea-bca7-bc764e2007e4; Wed, 15 Jul 2020 12:42:47 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BAE30AD11; Wed, 15 Jul 2020 12:42:49 +0000 (UTC) Subject: Re: [PATCH 2/2] evtchn/fifo: don't enforce higher than necessary alignment To: Julien Grall References: From: Jan Beulich Message-ID: <005381d5-3fb5-640f-002c-106c628a77a2@suse.com> Date: Wed, 15 Jul 2020 14:42:46 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , xen-devel Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On 15.07.2020 12:46, Julien Grall wrote: > On Wed, 15 Jul 2020, 12:17 Jan Beulich, wrote: > >> Neither the code nor the original commit provide any justification for >> the need to 8-byte align the struct in all cases. Enforce just as much >> alignment as the structure actually needs - 4 bytes - by using alignof() >> instead of a literal number. >> >> Take the opportunity and also >> - add so far missing validation that native and compat mode layouts of >> the structures actually match, >> - tie sizeof() expressions to the types of the fields we're actually >> after, rather than specifying the type explicitly (which in the >> general case risks a disconnect, even if there's close to zero risk in >> this particular case), >> - use ENXIO instead of EINVAL for the two cases of the address not >> satisfying the requirements, which will make an issue here better >> stand out at the call site. >> >> Signed-off-by: Jan Beulich >> --- >> I question the need for the array_index_nospec() here. Or else I'd >> expect map_vcpu_info() would also need the same. >> >> --- a/xen/common/event_fifo.c >> +++ b/xen/common/event_fifo.c >> @@ -504,6 +504,16 @@ static void setup_ports(struct domain *d >> } >> } >> >> +#ifdef CONFIG_COMPAT >> + >> +#include >> + >> +#define xen_evtchn_fifo_control_block evtchn_fifo_control_block >> +CHECK_evtchn_fifo_control_block; >> +#undef xen_evtchn_fifo_control_block >> + >> +#endif >> + >> int evtchn_fifo_init_control(struct evtchn_init_control *init_control) >> { >> struct domain *d = current->domain; >> @@ -523,19 +533,20 @@ int evtchn_fifo_init_control(struct evtc >> return -ENOENT; >> >> /* Must not cross page boundary. */ >> - if ( offset > (PAGE_SIZE - sizeof(evtchn_fifo_control_block_t)) ) >> - return -EINVAL; >> + if ( offset > (PAGE_SIZE - sizeof(*v->evtchn_fifo->control_block)) ) >> + return -ENXIO; >> >> /* >> * Make sure the guest controlled value offset is bounded even during >> * speculative execution. >> */ >> offset = array_index_nospec(offset, >> - PAGE_SIZE - >> sizeof(evtchn_fifo_control_block_t) + 1); >> + PAGE_SIZE - >> + sizeof(*v->evtchn_fifo->control_block) + >> 1); >> >> - /* Must be 8-bytes aligned. */ >> - if ( offset & (8 - 1) ) >> - return -EINVAL; >> + /* Must be suitably aligned. */ >> + if ( offset & (alignof(*v->evtchn_fifo->control_block) - 1) ) >> + return -ENXIO; >> > > A guest relying on this new alignment wouldn't work on older version of > Xen. So I don't think a guest would ever be able to use it. > > Therefore is it really worth the change? That's the question. One of your arguments for using a literal number also for the vCPU info mapping check was that here a literal number is used. The goal isn't so much relaxation of the interface, but making the code consistent as well as eliminating a (how I'd call it) kludge. Guests not caring to be able to run on older versions could also make use of the relaxation (which may be more relevant in 10 years time than it is now). Jan