Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3166C6FD1F for ; Tue, 14 Mar 2023 03:57:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229552AbjCND5F (ORCPT ); Mon, 13 Mar 2023 23:57:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbjCND5C (ORCPT ); Mon, 13 Mar 2023 23:57:02 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44B4C87A35 for ; Mon, 13 Mar 2023 20:56:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678766181; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gUTGoKigOjF7lnPsnySj5O1n6jQabFHTwPAHfAEzD+g=; b=G8iyA6zoIJk+7D5kiOqcAOXMLDnjtAq4BXcw9WZ9uXof6vemeot4h2kwJesHIV14DPA0Kz dt0HJ6craUDU9OE/CWcTnr3fpXkMEQEjM7GrDR/3hFlQVSQ/IiZ8g5hv9avISpaIgHugQ5 XlDkNpw7ngTjgzghzIERC78xXURFeh8= Received: from mail-oa1-f69.google.com (mail-oa1-f69.google.com [209.85.160.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-166-Bheuk85COgOp-hzELcc_RA-1; Mon, 13 Mar 2023 23:56:20 -0400 X-MC-Unique: Bheuk85COgOp-hzELcc_RA-1 Received: by mail-oa1-f69.google.com with SMTP id 586e51a60fabf-17270774b8fso8366176fac.3 for ; Mon, 13 Mar 2023 20:56:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678766179; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gUTGoKigOjF7lnPsnySj5O1n6jQabFHTwPAHfAEzD+g=; b=QEZorP9HXgjUKuR+Qtf+F3XMEHaBVa4h58JL+vwBy73mIcsyFVcOdKJqsQT9RG/7/j /nT1fFxyfso+rwuhC9ms8HayW82dKrP/UUrBR+PWFflDZ9deGydijZd8X5Ks1lRXfIEA /7e2BrX46ZmeIBPnOGGP5ABSB1jqJWCmSIcC1T5yCL0/ecPJ1bnhLEzk6hNzX3QPrWRH uyanYYDF9r2n3KWKWCNv7H7ZEVuh/r3EFffKFTIKAsriO2ZR+nWMmu5KyV+PYkxUqPh1 ir2RBURC5J4txJgf3lASNA++q+KVNvAaDgHoIUIF93FsW4KjZdEnJjKiukXULjM0gKd4 cW2A== X-Gm-Message-State: AO0yUKWtCvJPF2isTcJMJaK9JRjHzRTT2LgceNdMmJrLdUxt/fBsc84G CynHKiYvHD8bcvIx593fBAL3dteX+/vxZ5CKOgKOg7MUXsa+cInI/CJyjaxLApJGs5KsiYvEn/+ vL34EO6YtdCkmTl+eOHm7VFLgOWmj0X80+Owv9bB7 X-Received: by 2002:a9d:1984:0:b0:696:46dd:bec7 with SMTP id k4-20020a9d1984000000b0069646ddbec7mr491242otk.2.1678766179428; Mon, 13 Mar 2023 20:56:19 -0700 (PDT) X-Google-Smtp-Source: AK7set/8cD2YJCW/GyAom9yPG1fRPOW6omllIrRCSG8zrwMHOV27MDaBDu6YXAj5Pwq1SwhCEPZrqYs4Ze4SH/NyHBo= X-Received: by 2002:a9d:1984:0:b0:696:46dd:bec7 with SMTP id k4-20020a9d1984000000b0069646ddbec7mr491235otk.2.1678766179150; Mon, 13 Mar 2023 20:56:19 -0700 (PDT) MIME-Version: 1.0 References: <20230302113421.174582-1-sgarzare@redhat.com> <20230302113421.174582-4-sgarzare@redhat.com> In-Reply-To: <20230302113421.174582-4-sgarzare@redhat.com> From: Jason Wang Date: Tue, 14 Mar 2023 11:56:08 +0800 Message-ID: Subject: Re: [PATCH v2 3/8] vringh: replace kmap_atomic() with kmap_local_page() To: Stefano Garzarella Cc: virtualization@lists.linux-foundation.org, Andrey Zhadchenko , eperezma@redhat.com, netdev@vger.kernel.org, stefanha@redhat.com, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 2, 2023 at 7:34=E2=80=AFPM Stefano Garzarella wrote: > > kmap_atomic() is deprecated in favor of kmap_local_page(). It's better to mention the commit or code that introduces this. > > With kmap_local_page() the mappings are per thread, CPU local, can take > page-faults, and can be called from any context (including interrupts). > Furthermore, the tasks can be preempted and, when they are scheduled to > run again, the kernel virtual addresses are restored and still valid. > > kmap_atomic() is implemented like a kmap_local_page() which also disables > page-faults and preemption (the latter only for !PREEMPT_RT kernels, > otherwise it only disables migration). > > The code within the mappings/un-mappings in getu16_iotlb() and > putu16_iotlb() don't depend on the above-mentioned side effects of > kmap_atomic(), Note we used to use spinlock to protect simulators (at least until patch 7, so we probably need to re-order the patches at least) so I think this is only valid when: The vringh IOTLB helpers are not used in atomic context (e.g spinlock, interrupts). If yes, should we document this? (Or should we introduce a boolean to say whether an IOTLB variant can be used in an atomic context)? Thanks > so that mere replacements of the old API with the new one > is all that is required (i.e., there is no need to explicitly add calls > to pagefault_disable() and/or preempt_disable()). > > Signed-off-by: Stefano Garzarella > --- > > Notes: > v2: > - added this patch since checkpatch.pl complained about deprecation > of kmap_atomic() touched by next patch > > drivers/vhost/vringh.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c > index a1e27da54481..0ba3ef809e48 100644 > --- a/drivers/vhost/vringh.c > +++ b/drivers/vhost/vringh.c > @@ -1220,10 +1220,10 @@ static inline int getu16_iotlb(const struct vring= h *vrh, > if (ret < 0) > return ret; > > - kaddr =3D kmap_atomic(iov.bv_page); > + kaddr =3D kmap_local_page(iov.bv_page); > from =3D kaddr + iov.bv_offset; > *val =3D vringh16_to_cpu(vrh, READ_ONCE(*(__virtio16 *)from)); > - kunmap_atomic(kaddr); > + kunmap_local(kaddr); > > return 0; > } > @@ -1241,10 +1241,10 @@ static inline int putu16_iotlb(const struct vring= h *vrh, > if (ret < 0) > return ret; > > - kaddr =3D kmap_atomic(iov.bv_page); > + kaddr =3D kmap_local_page(iov.bv_page); > to =3D kaddr + iov.bv_offset; > WRITE_ONCE(*(__virtio16 *)to, cpu_to_vringh16(vrh, val)); > - kunmap_atomic(kaddr); > + kunmap_local(kaddr); > > return 0; > } > -- > 2.39.2 >