A compound of formula, or a pharmaceutically acceptable salt thereof: wherein: A is phenyl or 3-6 membered cycloalkyl; each of which is optionally substituted with --C 1-6 alkyl, cyano, -C 1-4 aminoalkyl, -C 1-4 alkoxyl, -C 1-6 haloalkyl, -C 1-4 haloalkoxyl, and halo; L is -C 1-6 alkylene-; each R 1 is independently selected from -C 1-6 alkyl, cyano, -C 1-4 aminoalkyl, -C 1-4 alkoxyl, - C 1-6 haloalkyl, -C 1-4 haloalkoxyl, and halo; each R 2 is H or -C 1-6 alkyl; R 3 is selected from -C 1-6 alkyl, -CN, -C 1-4 alkoxyl, -C 1-6 haloalkyl, -C 1-4 haloalkoxyl, halogen, -C R 3a, -C OR 3b, -C NR 3c R 3d, -P R 3e R 3f, -P (OR 3g)(OR 3h), -P (OR 3i)(R 3j), - S 2 R 3k, -S 2 NR 3l R 3m, -S R 3n, -NR 3o R 3p, -NR 3q C R 3r, -N(R 3s)C OR 3t and - NR 3u S 2 R 3v, wherein each of the -C 1-6 alkyl, -C 1-4 alkoxyl, -C 1-6 haloalkyl, and -C 1-4 haloalkoxyl is independently optionally substituted by hydroxyl, -NR 3w R 3x, -C 1-4 alkoxyl, -S 2 NR 3y R 3z, or-S 2 R 3a2; wherein each of R 3w, R 3x, R 3y, and R 3z is independently H, -C 1-4 alkyl or -C 1-6 haloalkyl and R 3a2 is -C 1-4 alkyl or -C 1-6 haloalkyl, or any two R 3 may combine with one atom to form a 5-6 membered fused heterocycloalkyl, wherein the heterocycloalkyl comprises one or two heteroatoms selected from N and S, and wherein the heterocycloalkyl is independently optionally substituted with one or two groups selected from -C 1-6 alkyl, -C 1-4 aminoalkyl -CN, -C 1-4 alkoxyl, halogen, -C 1-6 haloalkyl and -C 1-4 haloalkoxyl; each of R 3a, R 3b, R 3c, R 3d, R 3e, R 3f, R 3g, R 3h, R 3i, R 3j, R 3k, R 3n, R 3o, R 3p, R 3q, R 3r, R 3s, R 3t, R 3u, R 3v is independently selected from H, -C 1-6 alkyl and -C 1-6 haloalkyl; each of R 3l and R 3m is independently selected from H, -C 1-6 alkyl, -C 1-6 haloalkyl, - aminoalkyl, and -hydroxyalkyl, wherein the -C 1-6 alkyl is optionally further substituted by 3-6 membered cycloalkyl, and wherein the 3-6 membered cycloalkyl substituent is optionally further substituted by 1-2 halo; or R 23 and R 24 may combine with the N to form a 5-6 membered heterocycloalkyl, wherein the 5-6 membered heterocycloalkyl optionally further comprises one hetero atom selected from S and N; p is 1, 2 or 3; q is 0 or 1; and each of n and m is independently selected from 0, 1 and 2. A is phenyl or 3-6 membered cycloalkyl; each of which is optionally substituted with --C 1-6 alkyl, cyano, -C 1-4 aminoalkyl, -C 1-4 alkoxyl, -C 1-6 haloalkyl, -C 1-4 haloalkoxyl, and halo; L is -C 1-6 alkylene-; each R 1 is independently selected from -C 1-6 alkyl, cyano, -C 1-4 aminoalkyl, -C 1-4 alkoxyl, - C 1-6 haloalkyl, -C 1-4 haloalkoxyl, and halo; each R 2 is H or -C 1-6 alkyl; R 3 is selected from -C 1-6 alkyl, -CN, -C 1-4 alkoxyl, -C 1-6 haloalkyl, -C 1-4 haloalkoxyl, halogen, -C R 3a, -C OR 3b, -C NR 3c R 3d, -P R 3e R 3f, -P (OR 3g)(OR 3h), -P (OR 3i)(R 3j), - S 2 R 3k, -S 2 NR 3l R 3m, -S R 3n, -NR 3o R 3p, -NR 3q C R 3r, -N(R 3s)C OR 3t and - NR 3u S 2 R 3v, wherein each of the -C 1-6 alkyl, -C 1-4 alkoxyl, -C 1-6 haloalkyl, and -C 1-4 haloalkoxyl is independently optionally substituted by hydroxyl, -NR 3w R 3x, -C 1-4 alkoxyl, -S 2 NR 3y R 3z, or-S 2 R 3a2; wherein each of R 3w, R 3x, R 3y, and R 3z is independently H, -C 1-4 alkyl or -C 1-6 haloalkyl and R 3a2 is -C 1-4 alkyl or -C 1-6 haloalkyl, or any two R 3 may combine with one atom to form a 5-6 membered fused heterocycloalkyl, wherein the heterocycloalkyl comprises one or two heteroatoms selected from N and S, and wherein the heterocycloalkyl is independently optionally substituted with one or two groups selected from -C 1-6 alkyl, -C 1-4 aminoalkyl -CN, -C 1-4 alkoxyl, halogen, -C 1-6 haloalkyl and -C 1-4 haloalkoxyl; each of R 3a, R 3b, R 3c, R 3d, R 3e, R 3f, R 3g, R 3h, R 3i, R 3j, R 3k, R 3n, R 3o, R 3p, R 3q, R 3r, R 3s, R 3t, R 3u, R 3v is independently selected from H, -C 1-6 alkyl and -C 1-6 haloalkyl; each of R 3l and R 3m is independently selected from H, -C 1-6 alkyl, -C 1-6 haloalkyl, - aminoalkyl, and -hydroxyalkyl, wherein the -C 1-6 alkyl is optionally further substituted by 3-6 membered cycloalkyl, and wherein the 3-6 membered cycloalkyl substituent is optionally further substituted by 1-2 halo; or R 23 and R 24 may combine with the N to form a 5-6 membered heterocycloalkyl, wherein the 5-6 membered heterocycloalkyl optionally further comprises one hetero atom selected from S and N; p is 1, 2 or 3; q is 0 or 1; and each of n and m is independently selected from 0, 1 and 2.