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,URIBL_BLOCKED,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 71EECC433DF for ; Thu, 16 Jul 2020 12:07:11 +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 3BA702074B for ; Thu, 16 Jul 2020 12:07:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3BA702074B 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 1jw2f4-0006vi-Sj; Thu, 16 Jul 2020 12:06:50 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jw2f3-0006vd-LE for xen-devel@lists.xenproject.org; Thu, 16 Jul 2020 12:06:49 +0000 X-Inumbo-ID: d31373c2-c75c-11ea-94ab-12813bfff9fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d31373c2-c75c-11ea-94ab-12813bfff9fa; Thu, 16 Jul 2020 12:06:48 +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 7A511AFBF; Thu, 16 Jul 2020 12:06:51 +0000 (UTC) Subject: Re: [PATCH 2/2] evtchn/fifo: don't enforce higher than necessary alignment To: Julien Grall References: <005381d5-3fb5-640f-002c-106c628a77a2@suse.com> From: Jan Beulich Message-ID: <083b8df6-4587-b8dc-e501-4ed8e47aac51@suse.com> Date: Thu, 16 Jul 2020 14:06:49 +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 16:02, Julien Grall wrote: > On Wed, 15 Jul 2020, 14:42 Jan Beulich, wrote: > >> 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. >> > > Your commit message lead to think the relaxation is the key motivation to > change the code. I've added a clarifying sentence. >> 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 y ears time >> than it is now). > > > That makes sense. However, I am a bit concerned that an OS developer may > not notice the alignment problem with older version. > > I would suggest to at least document the alignment expected in the public > header. Done for v2. Jan