Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp79292rdd; Mon, 8 Jan 2024 18:46:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZomSK4stc5o9dG7anw81Yspa5mvOqYhFZ0MwJiFt8ICzrTwal2p5mb5x7gIIJJgso/wBH X-Received: by 2002:a17:90b:4a0e:b0:28c:f6ee:efce with SMTP id kk14-20020a17090b4a0e00b0028cf6eeefcemr98796pjb.23.1704768365847; Mon, 08 Jan 2024 18:46:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704768365; cv=none; d=google.com; s=arc-20160816; b=z5Naw6PLL8Sc6EhtPRttJZSTjJJ6LnHB1/x1u+9LwsVsvUOjqcB99cUZ1MZ/QVNL1P G4tAfE8RX/q5vd9JGKX/0ZN5klFXbcqOtxBP/46CwLb44cICX5YZFzTk2k1ZfVgH93zG P7Zm/cTZReVTFC9QNQdBSq503uTeV9xfOBV479Fw5kve+NF7Jded1OUHJeoWm8FweEz4 qDVbNRdMwvy5JlunNSXGe/R8uwqlw0CfOFeASra6ArwKKfMj9qOQ4Vs1x4JBUEb9/Ngf W8BmMS4h6Gc4Ef4P/3IFVdft5b6lEbi8JID5kKBaWmO2SwbIGmCNfPASd0fmEdVct6FO rZcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=1UfHonsI4VEuC3NubZaURhnQkvTv1O/puhLkP9wcq3A=; fh=YV9sm+238rh61pEFohXPzAfeYIwssiQmuyuLZ7d61Ek=; b=GQ1zFN6id/kihGPPYjBPId5/nWjy2NCTyfTUN9mdPZWAzX04A5Do/QzV6bugvpNk8O RfC8plLvYt0hzGTqvSJJNBpCuplo6wFaLqM64BWQakQhLIM8ZSgL+Ytk1unSbY8I2TSP vpthYoGHQ+Hg/oqjQrT+nIawL8o9ZYp7sF2T0dEZf/Gcsj+oKGa6uWJS5T7EZSxmHXJy uVXjzRNeNFiGBhAIkFjNbYx3XwVJWAJn3HFBlppLafLGBO+rPMB3/m5X2jsD93+pulZ/ iqSoXNGeLjCFf4akzg69k1TyvSbqqIjBI6w3Yfmq8Fi4y1oFrSoa1onToqqhJHCnjcXg C22Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-20295-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20295-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id sm6-20020a17090b2e4600b0028b88f8669fsi799531pjb.24.2024.01.08.18.46.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 18:46:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20295-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-20295-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20295-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 86A1628558F for ; Tue, 9 Jan 2024 02:46:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 181CB28FE; Tue, 9 Jan 2024 02:46:00 +0000 (UTC) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA22B257B for ; Tue, 9 Jan 2024 02:45:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4T8Fd31BrYz1Q7Pj; Tue, 9 Jan 2024 10:44:23 +0800 (CST) Received: from kwepemm600020.china.huawei.com (unknown [7.193.23.147]) by mail.maildlp.com (Postfix) with ESMTPS id 488B51402CB; Tue, 9 Jan 2024 10:45:54 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by kwepemm600020.china.huawei.com (7.193.23.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 9 Jan 2024 10:45:53 +0800 From: Peng Zhang To: , , , , , CC: , , Subject: [PATCH v2] swiotlb: check alloc_size before the allocation of a new memory pool Date: Tue, 9 Jan 2024 10:45:47 +0800 Message-ID: <20240109024547.3541529-1-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600020.china.huawei.com (7.193.23.147) From: ZhangPeng The allocation request for swiotlb contiguous memory greater than 128*2KB cannot be fulfilled because it exceeds the maximum contiguous memory limit. If the swiotlb memory we allocate is larger than 128*2KB, swiotlb_find_slots() will still schedule the allocation of a new memory pool, which will increase memory overhead. Fix it by adding a check with alloc_size no more than 128*2KB before scheduling the allocation of a new memory pool in swiotlb_find_slots(). Signed-off-by: ZhangPeng Reviewed-by: Petr Tesarik --- v1->v2: - Rebased on for-next branch per Christoph Hellwig - Added RB from Petr Tesarik kernel/dma/swiotlb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 97c298b210bc..b079a9a8e087 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -1136,6 +1136,9 @@ static int swiotlb_find_slots(struct device *dev, phys_addr_t orig_addr, int cpu, i; int index; + if (alloc_size > IO_TLB_SEGSIZE * IO_TLB_SIZE) + return -1; + cpu = raw_smp_processor_id(); for (i = 0; i < default_nareas; ++i) { index = swiotlb_search_area(dev, cpu, i, orig_addr, alloc_size, -- 2.25.1