From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 2002:a19:e8d:0:0:0:0:0 with SMTP id 135csp3902927lfo; Mon, 1 Feb 2021 17:30:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzk02SYF0q2otXBR/sjMxfdV6ZK6JBIzuE0squs0Igu52dMO4fZ2XIuBnU9geLE8tVkm3fW X-Received: by 2002:a05:6902:102d:: with SMTP id x13mr28048050ybt.264.1612229402555; Mon, 01 Feb 2021 17:30:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612229402; cv=none; d=google.com; s=arc-20160816; b=ltDYiM/AmVev6mldV6Bn+Ls6MpLB+59BLYEVrRMu48/fMi2bDA7CHFyAjnzCqcg/5s kqwX3tAsnMKwx7lhmNrpnagXXeLeJWG2Bp2tIGBmr86k12jy0z8hImam2PUBwP9ZVk3J X2apsZuBsX07lWnXfcq8XENTGOQl8vzrqoJsbY+RaQms8c2h0UOGc4mnxb0wW2qWoufw l1IW0h3Iwj8ZG/SxDS8QdvzHsQgY+3mPGfyhqp2D0Qq3S/dbOwPbv/Y4PDxIdwVPchic fgEyPF7UOXa5It5kuYO1UKnLy0ErcmeNvSz6bT8GP5RkYOunqIF5ihPpL8zSDr7NyKql EDIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject; bh=mjinziU0kcd/hKlGMHtFFJdPAfwYI4D7vCFIe0nkgqM=; b=qu6dMX++nzIkU9WOn7gfr3fJU05Ks9nleCb3Qdm6CXfiGgNAmqf8Hjn7zJ+YPNdG6k t6DJSn/gnHFuPbm1/Dk8z8Ln1wK5KS6X3RbZwLKot/yhLBIWXykRz55mb/2ipDBNwytK WxgzVLtg50Pz5oVCeMooANomoL7yWpwb964eC3tEY7DSNGZ/jGHMOAkQZoNzNZszw++o KdOpeoDNavaIY6Voi0fNRQnp/zvWOFCa5rFuPN/suNIXjLZYQYuf9/Y8knNMbgzhwbji /hm2N5aKzSo4R1vOIPFE3l2dkb2m6macdPD4S3JuG7mTYX6nvMEgVw8LA0U2ygWKc0lm aoNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j17si9453185ybg.350.2021.02.01.17.30.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Feb 2021 17:30:02 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Received: from localhost ([::1]:49716 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6kVz-0004q5-IZ for alex.bennee@linaro.org; Mon, 01 Feb 2021 20:30:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6kJt-0000M3-2u; Mon, 01 Feb 2021 20:17:29 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:3303) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6kJj-0007bn-5s; Mon, 01 Feb 2021 20:17:28 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DV6Lt4qCSzlDxQ; Tue, 2 Feb 2021 09:15:34 +0800 (CST) Received: from [10.174.184.42] (10.174.184.42) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.498.0; Tue, 2 Feb 2021 09:17:02 +0800 Subject: Re: [PATCH v2 2/2] accel: kvm: Add aligment assert for kvm_log_clear_one_slot To: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= , Peter Maydell , Paolo Bonzini , "Dr . David Alan Gilbert" , Andrew Jones , "Peter Xu" References: <20201217014941.22872-1-zhukeqian1@huawei.com> <20201217014941.22872-3-zhukeqian1@huawei.com> From: Keqian Zhu Message-ID: <47294e13-c9fe-78c8-db58-eaf0eec9496b@huawei.com> Date: Tue, 2 Feb 2021 09:17:01 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.184.42] X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhukeqian1@huawei.com; helo=szxga04-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zenghui Yu , wanghaibin.wang@huawei.com, jiangkunkun@huawei.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: M7Y5wEU42fyY Hi Philippe, On 2021/2/1 23:14, Philippe Mathieu-Daudé wrote: > Hi, > > On 12/17/20 2:49 AM, Keqian Zhu wrote: >> The parameters start and size are transfered from QEMU memory >> emulation layer. It can promise that they are TARGET_PAGE_SIZE >> aligned. However, KVM needs they are qemu_real_page_size aligned. >> >> Though no caller breaks this aligned requirement currently, we'd >> better add an explicit assert to avoid future breaking. >> >> Signed-off-by: Keqian Zhu >> --- >> accel/kvm/kvm-all.c | 7 +++++++ >> 1 file changed, 7 insertions(+) >> >> --- >> v2 >> - Address Andrew's commment (Use assert instead of return err). >> >> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c >> index f6b16a8df8..73b195cc41 100644 >> --- a/accel/kvm/kvm-all.c >> +++ b/accel/kvm/kvm-all.c >> @@ -692,6 +692,10 @@ out: >> #define KVM_CLEAR_LOG_ALIGN (qemu_real_host_page_size << KVM_CLEAR_LOG_SHIFT) >> #define KVM_CLEAR_LOG_MASK (-KVM_CLEAR_LOG_ALIGN) >> >> +/* >> + * As the granule of kvm dirty log is qemu_real_host_page_size, >> + * @start and @size are expected and restricted to align to it. >> + */ >> static int kvm_log_clear_one_slot(KVMSlot *mem, int as_id, uint64_t start, >> uint64_t size) >> { >> @@ -701,6 +705,9 @@ static int kvm_log_clear_one_slot(KVMSlot *mem, int as_id, uint64_t start, >> unsigned long *bmap_clear = NULL, psize = qemu_real_host_page_size; >> int ret; >> >> + /* Make sure start and size are qemu_real_host_page_size aligned */ >> + assert(QEMU_IS_ALIGNED(start | size, psize)); > > Why not return an error instead of aborting the VM? Yep, I return an error in v1. As suggested by Peter Xu: "Returning -EINVAL is the same as abort() currently - it'll just abort() at kvm_log_clear() instead." > >> /* >> * We need to extend either the start or the size or both to >> * satisfy the KVM interface requirement. Firstly, do the start >> > > . > Thanks for review. Keqian.