From patchwork Mon Jun 22 16:21:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 11618377 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FA1A90 for ; Mon, 22 Jun 2020 16:21:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F33220760 for ; Mon, 22 Jun 2020 16:21:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729655AbgFVQVy (ORCPT ); Mon, 22 Jun 2020 12:21:54 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:21496 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729671AbgFVQVx (ORCPT ); Mon, 22 Jun 2020 12:21:53 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05MG4VGB102606 for ; Mon, 22 Jun 2020 12:21:53 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31tysp8tfa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 22 Jun 2020 12:21:52 -0400 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 05MGC0iB140491 for ; Mon, 22 Jun 2020 12:21:52 -0400 Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 31tysp8te6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 12:21:52 -0400 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 05MG1BPv029895; Mon, 22 Jun 2020 16:21:49 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma05fra.de.ibm.com with ESMTP id 31sa37seg5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 16:21:49 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05MGLggm48824486 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Jun 2020 16:21:42 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 270F952052; Mon, 22 Jun 2020 16:21:42 +0000 (GMT) Received: from ibm-vm.ibmuc.com (unknown [9.145.9.197]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id CBAF15205F; Mon, 22 Jun 2020 16:21:41 +0000 (GMT) From: Claudio Imbrenda To: kvm@vger.kernel.org, pbonzini@redhat.com Cc: frankja@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v1 1/8] x86/cstart.S: initialize stack before using it Date: Mon, 22 Jun 2020 18:21:34 +0200 Message-Id: <20200622162141.279716-2-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200622162141.279716-1-imbrenda@linux.ibm.com> References: <20200622162141.279716-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-22_09:2020-06-22,2020-06-22 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 lowpriorityscore=0 clxscore=1015 cotscore=-2147483648 impostorscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 bulkscore=0 suspectscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006220117 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org It seems the 32-bit initialization code uses the stack before actually initializing it. Probably the boot loader leaves a reasonable value in the stack pointer so this issue has not been noticed before. Signed-off-by: Claudio Imbrenda --- x86/cstart.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x86/cstart.S b/x86/cstart.S index 38ac19b..fa62e09 100644 --- a/x86/cstart.S +++ b/x86/cstart.S @@ -96,13 +96,13 @@ MSR_GS_BASE = 0xc0000101 .globl start start: + mov $stacktop, %esp push %ebx call setup_multiboot call setup_libcflat mov mb_cmdline(%ebx), %eax mov %eax, __args call __setup_args - mov $stacktop, %esp setup_percpu_area call prepare_32 jmpl $8, $start32 From patchwork Mon Jun 22 16:21:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 11618367 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AFC4390 for ; Mon, 22 Jun 2020 16:21:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A10F62073E for ; Mon, 22 Jun 2020 16:21:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729497AbgFVQVs (ORCPT ); Mon, 22 Jun 2020 12:21:48 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:38880 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729358AbgFVQVs (ORCPT ); Mon, 22 Jun 2020 12:21:48 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05MG392I111758 for ; Mon, 22 Jun 2020 12:21:47 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31tyts8n0q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 22 Jun 2020 12:21:47 -0400 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 05MG3rl9114247 for ; Mon, 22 Jun 2020 12:21:47 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 31tyts8myd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 12:21:47 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 05MG0cp5022298; Mon, 22 Jun 2020 16:21:44 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 31sa37umsx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 16:21:44 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05MGLgZu10682750 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Jun 2020 16:21:42 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7D67152052; Mon, 22 Jun 2020 16:21:42 +0000 (GMT) Received: from ibm-vm.ibmuc.com (unknown [9.145.9.197]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 2D65C52050; Mon, 22 Jun 2020 16:21:42 +0000 (GMT) From: Claudio Imbrenda To: kvm@vger.kernel.org, pbonzini@redhat.com Cc: frankja@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v1 2/8] x86: add missing PAGE_ALIGN macro from page.h Date: Mon, 22 Jun 2020 18:21:35 +0200 Message-Id: <20200622162141.279716-3-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200622162141.279716-1-imbrenda@linux.ibm.com> References: <20200622162141.279716-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-22_09:2020-06-22,2020-06-22 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 phishscore=0 mlxlogscore=981 clxscore=1015 malwarescore=0 impostorscore=0 suspectscore=0 bulkscore=0 mlxscore=0 adultscore=0 priorityscore=1501 cotscore=-2147483648 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006220116 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The PAGE_ALIGN macro is present in all other page.h headers, including the generic one. This patch adds the missing PAGE_ALIGN macro to ib/x86/asm/page.h Signed-off-by: Claudio Imbrenda --- lib/x86/asm/page.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/x86/asm/page.h b/lib/x86/asm/page.h index 073580a..7e2a3dd 100644 --- a/lib/x86/asm/page.h +++ b/lib/x86/asm/page.h @@ -19,6 +19,8 @@ typedef unsigned long pgd_t; #ifndef __ASSEMBLY__ +#define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) + #ifdef __x86_64__ #define LARGE_PAGE_SIZE (512 * PAGE_SIZE) #else From patchwork Mon Jun 22 16:21:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 11618379 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA69260D for ; Mon, 22 Jun 2020 16:21:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B893B20767 for ; Mon, 22 Jun 2020 16:21:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729773AbgFVQVz (ORCPT ); Mon, 22 Jun 2020 12:21:55 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:7496 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729612AbgFVQVw (ORCPT ); Mon, 22 Jun 2020 12:21:52 -0400 Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05MG6k8T193662 for ; Mon, 22 Jun 2020 12:21:51 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31t02g7scy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 22 Jun 2020 12:21:50 -0400 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 05MFWbDD194097 for ; Mon, 22 Jun 2020 12:21:50 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 31t02g7s9s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 12:21:50 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 05MG0JQZ003831; Mon, 22 Jun 2020 16:21:45 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma03ams.nl.ibm.com with ESMTP id 31sa383njh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 16:21:45 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05MGLgi240632568 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Jun 2020 16:21:43 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C94065204E; Mon, 22 Jun 2020 16:21:42 +0000 (GMT) Received: from ibm-vm.ibmuc.com (unknown [9.145.9.197]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 8511452057; Mon, 22 Jun 2020 16:21:42 +0000 (GMT) From: Claudio Imbrenda To: kvm@vger.kernel.org, pbonzini@redhat.com Cc: frankja@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v1 3/8] lib: use PAGE_ALIGN Date: Mon, 22 Jun 2020 18:21:36 +0200 Message-Id: <20200622162141.279716-4-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200622162141.279716-1-imbrenda@linux.ibm.com> References: <20200622162141.279716-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-22_08:2020-06-22,2020-06-22 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 phishscore=0 adultscore=0 clxscore=1015 cotscore=-2147483648 mlxscore=0 bulkscore=0 mlxlogscore=841 suspectscore=2 lowpriorityscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006220116 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Since now PAGE_ALIGN is available in all architectures, start using it in common code to improve readability. Signed-off-by: Claudio Imbrenda --- lib/vmalloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/vmalloc.c b/lib/vmalloc.c index 5022a31..74b785c 100644 --- a/lib/vmalloc.c +++ b/lib/vmalloc.c @@ -41,7 +41,7 @@ void *vmap(phys_addr_t phys, size_t size) void *mem, *p; unsigned pages; - size = (size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); + size = PAGE_ALIGN(size); pages = size / PAGE_SIZE; mem = p = alloc_vpages(pages); @@ -60,7 +60,7 @@ static void *vm_memalign(size_t alignment, size_t size) unsigned pages; assert(alignment <= PAGE_SIZE); - size = (size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); + size = PAGE_ALIGN(size); pages = size / PAGE_SIZE; mem = p = alloc_vpages(pages); while (pages--) { @@ -104,7 +104,7 @@ void setup_vm() * so that it can be used to allocate page tables. */ if (!page_alloc_initialized()) { - base = (base + PAGE_SIZE - 1) & -PAGE_SIZE; + base = PAGE_ALIGN(base); top = top & -PAGE_SIZE; free_pages(phys_to_virt(base), top - base); } @@ -113,7 +113,7 @@ void setup_vm() phys_alloc_get_unused(&base, &top); page_root = setup_mmu(top); if (base != top) { - base = (base + PAGE_SIZE - 1) & -PAGE_SIZE; + base = PAGE_ALIGN(base); top = top & -PAGE_SIZE; free_pages(phys_to_virt(base), top - base); } From patchwork Mon Jun 22 16:21:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 11618371 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1A87B161F for ; Mon, 22 Jun 2020 16:21:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0C5C320768 for ; Mon, 22 Jun 2020 16:21:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729605AbgFVQVu (ORCPT ); Mon, 22 Jun 2020 12:21:50 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:48808 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729358AbgFVQVt (ORCPT ); Mon, 22 Jun 2020 12:21:49 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05MG0fKg017060 for ; Mon, 22 Jun 2020 12:21:49 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31tysprtxa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 22 Jun 2020 12:21:48 -0400 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 05MG0nOa018016 for ; Mon, 22 Jun 2020 12:21:47 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 31tysprtw2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 12:21:47 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 05MG124A013911; Mon, 22 Jun 2020 16:21:45 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma03fra.de.ibm.com with ESMTP id 31sa381ejt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 16:21:45 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05MGLhb647644920 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Jun 2020 16:21:43 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 302425204E; Mon, 22 Jun 2020 16:21:43 +0000 (GMT) Received: from ibm-vm.ibmuc.com (unknown [9.145.9.197]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id DA7F752063; Mon, 22 Jun 2020 16:21:42 +0000 (GMT) From: Claudio Imbrenda To: kvm@vger.kernel.org, pbonzini@redhat.com Cc: frankja@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v1 4/8] lib/alloc.c: add overflow check for calloc Date: Mon, 22 Jun 2020 18:21:37 +0200 Message-Id: <20200622162141.279716-5-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200622162141.279716-1-imbrenda@linux.ibm.com> References: <20200622162141.279716-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-22_09:2020-06-22,2020-06-22 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 mlxlogscore=955 mlxscore=0 lowpriorityscore=0 suspectscore=0 phishscore=0 clxscore=1015 cotscore=-2147483648 impostorscore=0 adultscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006220116 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add an overflow check for calloc to prevent potential multiplication overflow. Signed-off-by: Claudio Imbrenda --- lib/alloc.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/alloc.c b/lib/alloc.c index ed8f5f9..f4aa87a 100644 --- a/lib/alloc.c +++ b/lib/alloc.c @@ -6,9 +6,43 @@ void *malloc(size_t size) return memalign(sizeof(long), size); } +static bool mult_overflow(size_t a, size_t b) +{ +#if BITS_PER_LONG == 32 + /* 32 bit system, easy case: just use u64 */ + return (u64)a * (u64)b >= (1ULL << 32); +#else +#ifdef __SIZEOF_INT128__ + /* if __int128 is available use it (like the u64 case above) */ + unsigned __int128 res = a; + res *= b; + res >>= 64; + return res != 0; +#else + u64 tmp; + + if ((a >> 32) && (b >> 32)) + return true; + if (!(a >> 32) && !(b >> 32)) + return false; + tmp = (u32)a; + tmp *= (u32)b; + tmp >>= 32; + if (a < b) + tmp += a * (b >> 32); + else + tmp += b * (a >> 32); + return tmp >> 32; +#endif /* __SIZEOF_INT128__ */ +#endif /* BITS_PER_LONG == 32 */ +} + void *calloc(size_t nmemb, size_t size) { - void *ptr = malloc(nmemb * size); + void *ptr; + + assert(!mult_overflow(nmemb, size)); + ptr = malloc(nmemb * size); if (ptr) memset(ptr, 0, nmemb * size); return ptr; From patchwork Mon Jun 22 16:21:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 11618369 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83FEB60D for ; Mon, 22 Jun 2020 16:21:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71E3A2076A for ; Mon, 22 Jun 2020 16:21:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729597AbgFVQVt (ORCPT ); Mon, 22 Jun 2020 12:21:49 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:34932 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729511AbgFVQVs (ORCPT ); Mon, 22 Jun 2020 12:21:48 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05MG2vRJ103279 for ; Mon, 22 Jun 2020 12:21:48 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31tysv8tjw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 22 Jun 2020 12:21:48 -0400 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 05MG3OGj107144 for ; Mon, 22 Jun 2020 12:21:48 -0400 Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 31tysv8thk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 12:21:48 -0400 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 05MG1DXl029902; Mon, 22 Jun 2020 16:21:45 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma05fra.de.ibm.com with ESMTP id 31sa37seg7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 16:21:45 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05MGLhK148890048 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Jun 2020 16:21:43 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 83A4652050; Mon, 22 Jun 2020 16:21:43 +0000 (GMT) Received: from ibm-vm.ibmuc.com (unknown [9.145.9.197]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 36C9F52051; Mon, 22 Jun 2020 16:21:43 +0000 (GMT) From: Claudio Imbrenda To: kvm@vger.kernel.org, pbonzini@redhat.com Cc: frankja@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v1 5/8] lib: Fix a typo and add documentation comments Date: Mon, 22 Jun 2020 18:21:38 +0200 Message-Id: <20200622162141.279716-6-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200622162141.279716-1-imbrenda@linux.ibm.com> References: <20200622162141.279716-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-22_09:2020-06-22,2020-06-22 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=2 impostorscore=0 adultscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 clxscore=1015 phishscore=0 mlxscore=0 priorityscore=1501 malwarescore=0 cotscore=-2147483648 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006220117 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Fix a typo in lib/alloc_phys.h and add documentation comments to all functions in lib/vmalloc.h Signed-off-by: Claudio Imbrenda --- lib/alloc_phys.h | 2 +- lib/vmalloc.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/alloc_phys.h b/lib/alloc_phys.h index ea38f91..611aa70 100644 --- a/lib/alloc_phys.h +++ b/lib/alloc_phys.h @@ -39,7 +39,7 @@ extern void phys_alloc_show(void); /* * phys_alloc_get_unused allocates all remaining memory from the region * passed to phys_alloc_init, returning the newly allocated memory's base - * and top addresses. phys_allo_get_unused will still return base and top + * and top addresses. phys_alloc_get_unused will still return base and top * when no free memory is remaining, but base will equal top. */ extern void phys_alloc_get_unused(phys_addr_t *p_base, phys_addr_t *p_top); diff --git a/lib/vmalloc.h b/lib/vmalloc.h index 3658b80..2b563f4 100644 --- a/lib/vmalloc.h +++ b/lib/vmalloc.h @@ -3,15 +3,23 @@ #include +/* Allocate consecutive virtual pages (without backing) */ extern void *alloc_vpages(ulong nr); +/* Allocate one virtual page (without backing) */ extern void *alloc_vpage(void); +/* Set the top of the virtual address space */ extern void init_alloc_vpage(void *top); +/* Set up the virtual allocator; also sets up the page allocator if needed */ extern void setup_vm(void); +/* Set up paging */ extern void *setup_mmu(phys_addr_t top); +/* Walk the page table and resolve the virtual address to a physical address */ extern phys_addr_t virt_to_pte_phys(pgd_t *pgtable, void *virt); +/* Map the virtual address to the physical address for the given page tables */ extern pteval_t *install_page(pgd_t *pgtable, phys_addr_t phys, void *virt); +/* Map consecutive physical pages */ void *vmap(phys_addr_t phys, size_t size); #endif From patchwork Mon Jun 22 16:21:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 11618381 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C467E60D for ; Mon, 22 Jun 2020 16:21:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B6E1720767 for ; Mon, 22 Jun 2020 16:21:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729797AbgFVQV4 (ORCPT ); Mon, 22 Jun 2020 12:21:56 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:49046 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729718AbgFVQVz (ORCPT ); Mon, 22 Jun 2020 12:21:55 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05MGCcXL030873 for ; Mon, 22 Jun 2020 12:21:54 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 31spnv7txs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 22 Jun 2020 12:21:53 -0400 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 05MGLge3050896 for ; Mon, 22 Jun 2020 12:21:50 -0400 Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0b-001b2d01.pphosted.com with ESMTP id 31spnv7twp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 12:21:50 -0400 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 05MFxxxS025826; Mon, 22 Jun 2020 16:21:46 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma01fra.de.ibm.com with ESMTP id 31sa381j27-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 16:21:46 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05MGLhfK46989564 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Jun 2020 16:21:44 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD30B52050; Mon, 22 Jun 2020 16:21:43 +0000 (GMT) Received: from ibm-vm.ibmuc.com (unknown [9.145.9.197]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 8AAFA5204E; Mon, 22 Jun 2020 16:21:43 +0000 (GMT) From: Claudio Imbrenda To: kvm@vger.kernel.org, pbonzini@redhat.com Cc: frankja@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v1 6/8] lib/vmalloc: fix potential race and non-standard pointer arithmetic Date: Mon, 22 Jun 2020 18:21:39 +0200 Message-Id: <20200622162141.279716-7-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200622162141.279716-1-imbrenda@linux.ibm.com> References: <20200622162141.279716-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-22_09:2020-06-22,2020-06-22 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 spamscore=0 adultscore=0 bulkscore=0 cotscore=-2147483648 impostorscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 malwarescore=0 priorityscore=1501 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006220116 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The pointer vfree_top should only be accessed with the lock held, so make sure we return a local copy of the pointer taken safely inside the lock. Also avoid doing pointer arithmetic on void pointers. Gcc allows it but it is an ugly hack. Use uintptr_t for doing maths on the pointer. This will also come useful in upcoming patches. Signed-off-by: Claudio Imbrenda --- lib/vmalloc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/vmalloc.c b/lib/vmalloc.c index 74b785c..83e34aa 100644 --- a/lib/vmalloc.c +++ b/lib/vmalloc.c @@ -20,10 +20,16 @@ static void *page_root; void *alloc_vpages(ulong nr) { + uintptr_t ptr; + spin_lock(&lock); - vfree_top -= PAGE_SIZE * nr; + ptr = (uintptr_t)vfree_top; + ptr -= PAGE_SIZE * nr; + vfree_top = (void *)ptr; spin_unlock(&lock); - return vfree_top; + + /* Cannot return vfree_top here, we are outside the lock! */ + return (void *)ptr; } void *alloc_vpage(void) From patchwork Mon Jun 22 16:21:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 11618373 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A795C90 for ; Mon, 22 Jun 2020 16:21:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 99F732076A for ; Mon, 22 Jun 2020 16:21:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729669AbgFVQVv (ORCPT ); Mon, 22 Jun 2020 12:21:51 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41290 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729519AbgFVQVt (ORCPT ); Mon, 22 Jun 2020 12:21:49 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05MG0fON017059 for ; Mon, 22 Jun 2020 12:21:49 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31tysprty0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 22 Jun 2020 12:21:49 -0400 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 05MG0iFA017289 for ; Mon, 22 Jun 2020 12:21:48 -0400 Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 31tysprtws-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 12:21:48 -0400 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 05MG1JhO029912; Mon, 22 Jun 2020 16:21:46 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma05fra.de.ibm.com with ESMTP id 31sa37seg8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 16:21:46 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05MGLifU61866298 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Jun 2020 16:21:44 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 41E875204E; Mon, 22 Jun 2020 16:21:44 +0000 (GMT) Received: from ibm-vm.ibmuc.com (unknown [9.145.9.197]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id E431652051; Mon, 22 Jun 2020 16:21:43 +0000 (GMT) From: Claudio Imbrenda To: kvm@vger.kernel.org, pbonzini@redhat.com Cc: frankja@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v1 7/8] lib/alloc_page: make get_order return unsigned int Date: Mon, 22 Jun 2020 18:21:40 +0200 Message-Id: <20200622162141.279716-8-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200622162141.279716-1-imbrenda@linux.ibm.com> References: <20200622162141.279716-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-22_09:2020-06-22,2020-06-22 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 mlxlogscore=904 mlxscore=0 lowpriorityscore=0 suspectscore=2 phishscore=0 clxscore=1015 cotscore=-2147483648 impostorscore=0 adultscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006220116 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Since get_order never returns a negative value, it makes sense to make it return an unsigned int. The returned value will be in practice always very small, a u8 would probably also do the trick. Signed-off-by: Claudio Imbrenda --- lib/alloc_page.h | 2 +- lib/alloc_page.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/alloc_page.h b/lib/alloc_page.h index e6a51d2..6181299 100644 --- a/lib/alloc_page.h +++ b/lib/alloc_page.h @@ -15,6 +15,6 @@ void *alloc_pages(unsigned long order); void free_page(void *page); void free_pages(void *mem, unsigned long size); void free_pages_by_order(void *mem, unsigned long order); -int get_order(size_t size); +unsigned int get_order(size_t size); #endif diff --git a/lib/alloc_page.c b/lib/alloc_page.c index 7c8461a..8769c3f 100644 --- a/lib/alloc_page.c +++ b/lib/alloc_page.c @@ -176,7 +176,7 @@ void page_alloc_ops_enable(void) alloc_ops = &page_alloc_ops; } -int get_order(size_t size) +unsigned int get_order(size_t size) { return is_power_of_2(size) ? fls(size) : fls(size) + 1; } From patchwork Mon Jun 22 16:21:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 11618375 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF71C90 for ; Mon, 22 Jun 2020 16:21:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C3D0520767 for ; Mon, 22 Jun 2020 16:21:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729603AbgFVQVw (ORCPT ); Mon, 22 Jun 2020 12:21:52 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:49586 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729599AbgFVQVu (ORCPT ); Mon, 22 Jun 2020 12:21:50 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05MG2wIA103390 for ; Mon, 22 Jun 2020 12:21:50 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31tysv8tm2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 22 Jun 2020 12:21:50 -0400 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 05MG3I2b106254 for ; Mon, 22 Jun 2020 12:21:49 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 31tysv8tjg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 12:21:49 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 05MG30Qx015929; Mon, 22 Jun 2020 16:21:47 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03fra.de.ibm.com with ESMTP id 31sa381ejv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 16:21:46 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05MGLig860686702 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Jun 2020 16:21:44 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 98C6F52051; Mon, 22 Jun 2020 16:21:44 +0000 (GMT) Received: from ibm-vm.ibmuc.com (unknown [9.145.9.197]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 491CE52050; Mon, 22 Jun 2020 16:21:44 +0000 (GMT) From: Claudio Imbrenda To: kvm@vger.kernel.org, pbonzini@redhat.com Cc: frankja@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v1 8/8] lib/vmalloc: add locking and a check for initialization Date: Mon, 22 Jun 2020 18:21:41 +0200 Message-Id: <20200622162141.279716-9-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200622162141.279716-1-imbrenda@linux.ibm.com> References: <20200622162141.279716-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-22_09:2020-06-22,2020-06-22 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=2 impostorscore=0 adultscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 clxscore=1015 phishscore=0 mlxscore=0 priorityscore=1501 malwarescore=0 cotscore=-2147483648 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006220117 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Make sure init_alloc_vpage is never called when vmalloc is in use. Get both init_alloc_vpage and setup_vm to use the lock. For setup_vm we only check at the end because at least on some architectures setup_mmu can call init_alloc_vpage, which would cause a deadlock. Signed-off-by: Claudio Imbrenda --- lib/vmalloc.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/vmalloc.c b/lib/vmalloc.c index 83e34aa..10f15af 100644 --- a/lib/vmalloc.c +++ b/lib/vmalloc.c @@ -37,11 +37,6 @@ void *alloc_vpage(void) return alloc_vpages(1); } -void init_alloc_vpage(void *top) -{ - vfree_top = top; -} - void *vmap(phys_addr_t phys, size_t size) { void *mem, *p; @@ -96,6 +91,14 @@ void __attribute__((__weak__)) find_highmem(void) { } +void init_alloc_vpage(void *top) +{ + spin_lock(&lock); + assert(alloc_ops != &vmalloc_ops); + vfree_top = top; + spin_unlock(&lock); +} + void setup_vm() { phys_addr_t base, top; @@ -124,5 +127,8 @@ void setup_vm() free_pages(phys_to_virt(base), top - base); } + spin_lock(&lock); + assert(alloc_ops != &vmalloc_ops); alloc_ops = &vmalloc_ops; + spin_unlock(&lock); }