Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2516630rwd; Fri, 26 May 2023 07:34:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7oMlo0510AVjW9vNrQfTkNVSKZBq8TwHJ82U6asjU7zPLliKACCFZ7hFd0GrsjzhZg6e7e X-Received: by 2002:a05:6a20:8f0a:b0:10c:2c30:4765 with SMTP id b10-20020a056a208f0a00b0010c2c304765mr2946051pzk.1.1685111655934; Fri, 26 May 2023 07:34:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685111655; cv=none; d=google.com; s=arc-20160816; b=ToF7+cdy0CW1JnCeTixSxXAP77jvQiGfOeDu5f3ZN3pWXnwgZd1QuwB/PCXDgfHKX4 PNklkPa8FmEE6JsdfRxa6weA62ycFMR6EtnUt3vNyB/2CRzMTiLzhbIolrgp99AdySHl dzqWuKKmEVisiq9i9lClbUztDvTOJ4WkjSL+7YJKqS2aU+GjEACFtCMNG4r6sBgF903d zGoGNiMgoisCRFHBiHih+DSqoKYwp1pIJklACckV3wGZAW1LeARIC2DWS6dCeSV79k8P 8Rh8WObZLss3m2xXoxCjpRmXEFaWqWEyza5XDSia6IeWOGJJeypTjO1TNcnnfal60xf+ 3xdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jPGukvQXP4Tai7PUqcbnIswr++Y11hB7rT1QDpn/afo=; b=IEBezBoBzKQU0Ju2I0JF6oJ9WFAZ3UA0WeGnVmNJdUpKmDxmzrAw/K1dSs6rTI6OJ7 qJMTNSNsIy8Zr6K1tkk5SXELvfcEFbeabhHH56QWzM+Hd5Ypb3Yv3+JqFOQPlGq3NKd9 /1c4iTo+l7iQRdSc6oVBahgTevzLV2kuhvNtGs4pOT0qDl5QSk0TF0vxcAJ/x0/aULBi dvtCJrI39oIrloUNZKGJ/1/qsS9Ek/ccPX72cydCUUWL9G4KBzKtY+dV1Zlfd3rDEebO VkArGhY+0Z32K8OSIJMDp/U/dcAIYP4Z6H5pf63mfhZpLi9NZTn0aO/ZIMq/XcHV6WLN hHPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Nlk7HVaS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w129-20020a623087000000b006452ad45992si3963561pfw.3.2023.05.26.07.34.00; Fri, 26 May 2023 07:34:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Nlk7HVaS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243920AbjEZOcZ (ORCPT + 99 others); Fri, 26 May 2023 10:32:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237413AbjEZOcN (ORCPT ); Fri, 26 May 2023 10:32:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65BBCE62 for ; Fri, 26 May 2023 07:31:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685111485; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jPGukvQXP4Tai7PUqcbnIswr++Y11hB7rT1QDpn/afo=; b=Nlk7HVaS7Ojsw59gG+Indrde5s5LkTPXDUgDBSXV+KeuDwDEfDnrDpYbjjMETU/8Jl7znT oylTY9Kj3m8X8yKH3mGHL6jlpZkSei8ad9xBNuSzCXdDJVdGPCf78mJV7Oau2s7FWRdTrM SVzzwuSr0yKnyWEjEJa1RtS+zpBmjks= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-29-Ivy8e833NRWSYrtoVTgS-g-1; Fri, 26 May 2023 10:31:21 -0400 X-MC-Unique: Ivy8e833NRWSYrtoVTgS-g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A6DD811E92; Fri, 26 May 2023 14:31:19 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4D0C140E961; Fri, 26 May 2023 14:31:17 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , Herbert Xu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-crypto@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 3/8] crypto: af_alg: Pin pages rather than ref'ing if appropriate Date: Fri, 26 May 2023 15:30:59 +0100 Message-Id: <20230526143104.882842-4-dhowells@redhat.com> In-Reply-To: <20230526143104.882842-1-dhowells@redhat.com> References: <20230526143104.882842-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Convert AF_ALG to use iov_iter_extract_pages() instead of iov_iter_get_pages(). This will pin pages or leave them unaltered rather than getting a ref on them as appropriate to the iterator. The pages need to be pinned for DIO-read rather than having refs taken on them to prevent VM copy-on-write from malfunctioning during a concurrent fork() (the result of the I/O would otherwise end up only visible to the child process and not the parent). Signed-off-by: David Howells cc: Herbert Xu cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: linux-crypto@vger.kernel.org cc: netdev@vger.kernel.org --- crypto/af_alg.c | 10 +++++++--- include/crypto/if_alg.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 5f7252a5b7b4..7caff10df643 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -533,14 +533,17 @@ static const struct net_proto_family alg_family = { int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len) { + struct page **pages = sgl->pages; size_t off; ssize_t n; int npages, i; - n = iov_iter_get_pages2(iter, sgl->pages, len, ALG_MAX_PAGES, &off); + n = iov_iter_extract_pages(iter, &pages, len, ALG_MAX_PAGES, 0, &off); if (n < 0) return n; + sgl->need_unpin = iov_iter_extract_will_pin(iter); + npages = DIV_ROUND_UP(off + n, PAGE_SIZE); if (WARN_ON(npages == 0)) return -EINVAL; @@ -573,8 +576,9 @@ void af_alg_free_sg(struct af_alg_sgl *sgl) { int i; - for (i = 0; i < sgl->npages; i++) - put_page(sgl->pages[i]); + if (sgl->need_unpin) + for (i = 0; i < sgl->npages; i++) + unpin_user_page(sgl->pages[i]); } EXPORT_SYMBOL_GPL(af_alg_free_sg); diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h index 7e76623f9ec3..46494b33f5bc 100644 --- a/include/crypto/if_alg.h +++ b/include/crypto/if_alg.h @@ -59,6 +59,7 @@ struct af_alg_sgl { struct scatterlist sg[ALG_MAX_PAGES + 1]; struct page *pages[ALG_MAX_PAGES]; unsigned int npages; + bool need_unpin; }; /* TX SGL entry */